aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/news.txt2
-rw-r--r--runtime/lua/vim/lsp/buf.lua11
-rw-r--r--runtime/lua/vim/lsp/protocol.lua2
3 files changed, 12 insertions, 3 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 4667af906f..1b9c3a463f 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -309,6 +309,8 @@ LSP
• |vim.lsp.config()| has been added to define default configurations for
servers. In addition, configurations can be specified in `lsp/<name>.lua`.
• |vim.lsp.enable()| has been added to enable servers.
+• |vim.lsp.buf.code_action()| resolves the `command` property during the
+ `codeAction/resolve` request.
LUA
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 47f41b43aa..094be17c83 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -1129,6 +1129,7 @@ local function on_code_action_results(results, opts)
if not choice then
return
end
+
-- textDocument/codeAction can return either Command[] or CodeAction[]
--
-- CodeAction
@@ -1140,12 +1141,18 @@ local function on_code_action_results(results, opts)
-- title: string
-- command: string
-- arguments?: any[]
- --
+
local client = assert(lsp.get_client_by_id(choice.ctx.client_id))
local action = choice.action
local bufnr = assert(choice.ctx.bufnr, 'Must have buffer number')
- if not action.edit and client:supports_method(ms.codeAction_resolve) then
+ -- Only code actions are resolved, so if we have a command, just apply it.
+ if type(action.title) == 'string' and type(action.command) == 'string' then
+ apply_action(action, client, choice.ctx)
+ return
+ end
+
+ if not action.edit or not action.command and client:supports_method(ms.codeAction_resolve) then
client:request(ms.codeAction_resolve, action, function(err, resolved_action)
if err then
if action.command then
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 7975006f9d..feff9adbd0 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -424,7 +424,7 @@ function protocol.make_client_capabilities()
isPreferredSupport = true,
dataSupport = true,
resolveSupport = {
- properties = { 'edit' },
+ properties = { 'edit', 'command' },
},
},
codeLens = {