aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp
diff options
context:
space:
mode:
authorMathias Fußenegger <mfussenegger@users.noreply.github.com>2023-06-20 18:36:18 +0200
committerGitHub <noreply@github.com>2023-06-20 18:36:18 +0200
commit64f2691a984a5b1e2958d5656a910054982a6f0e (patch)
treeb02c4e0f3f5beefbe50e7193793e254df3cd9d66 /runtime/lua/vim/lsp
parent19eef8156bdd3539f10c9a39494cb64b88d777f5 (diff)
downloadrneovim-64f2691a984a5b1e2958d5656a910054982a6f0e.tar.gz
rneovim-64f2691a984a5b1e2958d5656a910054982a6f0e.tar.bz2
rneovim-64f2691a984a5b1e2958d5656a910054982a6f0e.zip
refactor(lsp): extract common execute command functionality (#24065)
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r--runtime/lua/vim/lsp/buf.lua18
-rw-r--r--runtime/lua/vim/lsp/codelens.lua24
-rw-r--r--runtime/lua/vim/lsp/types.lua2
3 files changed, 6 insertions, 38 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index c3deffc1f9..45056cf272 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -646,21 +646,7 @@ local function on_code_action_results(results, ctx, options)
end
if action.command then
local command = type(action.command) == 'table' and action.command or action
- local fn = client.commands[command.command] or vim.lsp.commands[command.command]
- if fn then
- local enriched_ctx = vim.deepcopy(ctx)
- enriched_ctx.client_id = client.id
- fn(command, enriched_ctx)
- else
- -- Not using command directly to exclude extra properties,
- -- see https://github.com/python-lsp/python-lsp-server/issues/146
- local params = {
- command = command.command,
- arguments = command.arguments,
- workDoneToken = command.workDoneToken,
- }
- client.request('workspace/executeCommand', params, nil, ctx.bufnr)
- end
+ client._exec_cmd(command, ctx)
end
end
@@ -697,7 +683,7 @@ local function on_code_action_results(results, ctx, options)
return
end
apply_action(resolved_action, client)
- end)
+ end, ctx.bufnr)
else
apply_action(action, client)
end
diff --git a/runtime/lua/vim/lsp/codelens.lua b/runtime/lua/vim/lsp/codelens.lua
index e26bdcc6d4..5acfe90d5e 100644
--- a/runtime/lua/vim/lsp/codelens.lua
+++ b/runtime/lua/vim/lsp/codelens.lua
@@ -33,30 +33,12 @@ local function execute_lens(lens, bufnr, client_id)
local client = vim.lsp.get_client_by_id(client_id)
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
- local command = lens.command
- local fn = client.commands[command.command] or 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 command_provider = client.server_capabilities.executeCommandProvider
- local commands = type(command_provider) == 'table' and command_provider.commands or {}
- if not vim.list_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(...)
+
+ client._exec_cmd(lens.command, { bufnr = bufnr }, function(...)
local result = vim.lsp.handlers['workspace/executeCommand'](...)
M.refresh()
return result
- end, bufnr)
+ end)
end
--- Return all lenses for the given buffer
diff --git a/runtime/lua/vim/lsp/types.lua b/runtime/lua/vim/lsp/types.lua
index 108aeeb922..cdfbcfb11b 100644
--- a/runtime/lua/vim/lsp/types.lua
+++ b/runtime/lua/vim/lsp/types.lua
@@ -1,6 +1,6 @@
---@meta
----@alias lsp-handler fun(err: lsp.ResponseError|nil, result: any, context: lsp.HandlerContext, config: table|nil)
+---@alias lsp-handler fun(err: lsp.ResponseError|nil, result: any, context: lsp.HandlerContext, config: table|nil): any?
---@class lsp.HandlerContext
---@field method string