diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2021-09-28 18:19:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 09:19:19 -0700 |
commit | 19a77cd5a7cbd304e57118d6a09798223b6d2dbf (patch) | |
tree | 544e9b18033ce0ace7feaae20968db97c44c9eb2 /runtime/lua/vim/lsp/codelens.lua | |
parent | ff18a8bcc4749c7ee169b63ef05ac1238d2de26e (diff) | |
download | rneovim-19a77cd5a7cbd304e57118d6a09798223b6d2dbf.tar.gz rneovim-19a77cd5a7cbd304e57118d6a09798223b6d2dbf.tar.bz2 rneovim-19a77cd5a7cbd304e57118d6a09798223b6d2dbf.zip |
feat(lsp): add client command support to codelens (#15820)
Also adds a check against the server capabilities to fix
https://github.com/neovim/neovim/issues/15183
Diffstat (limited to 'runtime/lua/vim/lsp/codelens.lua')
-rw-r--r-- | runtime/lua/vim/lsp/codelens.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/codelens.lua b/runtime/lua/vim/lsp/codelens.lua index 9cedb2f1db..20b203fe99 100644 --- a/runtime/lua/vim/lsp/codelens.lua +++ b/runtime/lua/vim/lsp/codelens.lua @@ -31,10 +31,24 @@ local function execute_lens(lens, bufnr, client_id) local line = lens.range.start.line api.nvim_buf_clear_namespace(bufnr, namespaces[client_id], line, line + 1) + local command = lens.command + local fn = vim.lsp.commands[command.command] + if fn then + fn(command, { bufnr = bufnr, client_id = client_id }) + return + end -- Need to use the client that returned the lens → must not use buf_request local client = vim.lsp.get_client_by_id(client_id) assert(client, 'Client is required to execute lens, client_id=' .. client_id) - client.request('workspace/executeCommand', lens.command, function(...) + local command_provider = client.server_capabilities.executeCommandProvider + local commands = type(command_provider) == 'table' and command_provider.commands or {} + if not vim.tbl_contains(commands, command.command) then + vim.notify(string.format( + "Language server does not support command `%s`. This command may require a client extension.", command.command), + vim.log.levels.WARN) + return + end + client.request('workspace/executeCommand', command, function(...) local result = vim.lsp.handlers['workspace/executeCommand'](...) M.refresh() return result |