mirror of
https://github.com/nvim-neotest/nvim-nio.git
synced 2024-09-08 02:25:48 +02:00
feat(lsp): add supports_method to lsp client (#21)
This commit is contained in:
parent
7969e0a8ff
commit
a428f30911
2 changed files with 28 additions and 1 deletions
|
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)
|
||||
|
|
|
@ -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…
Reference in a new issue