Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): add supports_method to nio.lsp.Client #21

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lua/nio/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ nio.lsp = {}
---@field request nio.lsp.RequestClient Interface to all requests that can be sent by the client
---@field notify nio.lsp.NotifyClient Interface to all notifications that can be sent by the client
---@field server_capabilities nio.lsp.types.ServerCapabilities
---@field supports_method table<string, fun(opts: { bufnr : number }): boolean> Check if a method is supported by the client

local async_request = tasks.wrap(function(client, method, params, bufnr, request_id_future, cb)
local success, req_id = client.request(method, params, cb, bufnr)
Expand Down Expand Up @@ -58,7 +59,7 @@ function nio.lsp.get_client_by_id(id)
end

--- Create an async client for the given client
---@param client table Neovim core LSP client object
---@param client vim.lsp.Client Neovim core LSP client object
---@return nio.lsp.Client
function nio.lsp.convert_client(client)
local n = require("nio")
Expand All @@ -70,6 +71,14 @@ function nio.lsp.convert_client(client)

return {
server_capabilities = client.server_capabilities,
supports_method = setmetatable({}, {
__index = function(_, method)
method = convert_method(method)
return function(opts)
return client.supports_method(method, opts)
end
end,
}),
notify = setmetatable({}, {
__index = function(_, method)
method = convert_method(method)
Expand Down
18 changes: 18 additions & 0 deletions tests/lsp_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,22 @@ describe("lsp client", function()
assert.False(success)
assert.Not.Nil(string.find(err, "Client 1 has shut down"))
end)

a.it("returns a response for whether a method is supported", function()
local expected_result = false
local expected_method = "textDocument/diagnostic"
local expected_opts = { a = "b" }
vim.lsp.get_client_by_id = function(id)
return {
supports_method = function(method, opts)
assert.equals(expected_method, method)
assert.same(expected_opts, opts)
return expected_result
end,
}
end
local client = nio.lsp.get_client_by_id(1)
local result = client.supports_method.textDocument_diagnostic(expected_opts)
assert.equals(expected_result, result)
end)
end)
Loading