Skip to content

Commit

Permalink
chore: code tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2024
1 parent 66ee2b5 commit abcd1c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lua/csharpls_extended.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local M = {}
-- return string.gsub(str, "[/\\]", ".")
-- end

M.csharp_host = "csharp:/metadata";
M.csharp_host = "csharp:/metadata"

M.client_name = "csharp_ls"

Expand All @@ -30,6 +30,7 @@ M.is_lsp_url = function(uri)
end

-- get client
--- @return vim.lsp.Client | nil
M.get_csharpls_client = function()
local clients = vim.lsp.get_clients({ buffer = 0 })
for _, client in pairs(clients) do
Expand All @@ -41,6 +42,15 @@ M.get_csharpls_client = function()
return nil
end

--- @class buf_from_metadata.result
--- @inlinedoc
--- @field source string
--- @field assemblyName string
---
--- @param result buf_from_metadata.result
--- @param client_id integer
---
--- @return integer
M.buf_from_metadata = function(result, client_id)
local normalized = string.gsub(result.source, "\r\n", "\n")
local source_lines = utils.split(normalized, "\n")
Expand All @@ -63,7 +73,7 @@ M.buf_from_metadata = function(result, client_id)
-- attach lsp client ??
vim.lsp.buf_attach_client(bufnr, client_id)

return bufnr, file_name
return bufnr
end

--- @class handle_locations.ret
Expand Down Expand Up @@ -115,11 +125,11 @@ M.get_metadata = function(locations, offset_encoding)
local result, err = client.request_sync("csharp/metadata", params, 10000, 0)
--print(result.result.source)
if not err and result ~= nil then
local bufnr, name = M.buf_from_metadata(result.result, client.id)
local bufnr = M.buf_from_metadata(result.result, client.id)
-- change location name to the one returned from metadata
-- alternative is to open buffer under location uri
-- not sure which one is better
loc.uri = "file://" .. name
loc.uri = vim.uri_from_bufnr(bufnr)
table.insert(fetched, {
filename = vim.uri_to_fname(loc.uri),
lnum = loc.range.start.line + 1,
Expand Down
3 changes: 3 additions & 0 deletions lua/csharpls_extended/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ U.split = function(str, delimiter)
return result
end

--- used to find the buffer id
--- @param name string
--- @return integer
U.get_or_create_buf = function(name)
local buffers = vim.api.nvim_list_bufs()
for _, buf in pairs(buffers) do
Expand Down
3 changes: 3 additions & 0 deletions lua/telescope/_extensions/csharpls_definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ local M = {
title = "csharpls definition"
};

--- @param locations lsp.Location[] | lsp.LocationLink[]
--- @param offset_encoding string
--- @param opts any
M.telescope_handle_location = function(locations, offset_encoding, opts)
local fetched = csharpls_extend.get_metadata(locations, offset_encoding)

Expand Down

0 comments on commit abcd1c8

Please sign in to comment.