aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2021-09-22 11:42:56 -0700
committerGitHub <noreply@github.com>2021-09-22 11:42:56 -0700
commit248974a4c6f1b76f0e33cd355c5c36a80ce01fac (patch)
treee6b806f98d2731ac06f464e34c8cda223901c22d /runtime/lua/vim/lsp/handlers.lua
parentec447b879854e7bb1a54ab2b4565cd51e43fadfa (diff)
parent6c03601e3adb4c3c4d47f148df8df20401b88677 (diff)
downloadrneovim-248974a4c6f1b76f0e33cd355c5c36a80ce01fac.tar.gz
rneovim-248974a4c6f1b76f0e33cd355c5c36a80ce01fac.tar.bz2
rneovim-248974a4c6f1b76f0e33cd355c5c36a80ce01fac.zip
Merge pull request #14115 from mfussenegger/lsp-commands
lsp: Add a registry for client side code action commands
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r--runtime/lua/vim/lsp/handlers.lua35
1 files changed, 22 insertions, 13 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 918666ab27..c2f2b870f7 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -110,7 +110,7 @@ M['client/registerCapability'] = function(_, _, ctx)
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
-M['textDocument/codeAction'] = function(_, result)
+M['textDocument/codeAction'] = function(_, result, ctx)
if result == nil or vim.tbl_isempty(result) then
print("No code actions available")
return
@@ -127,19 +127,28 @@ M['textDocument/codeAction'] = function(_, result)
if choice < 1 or choice > #result then
return
end
- local action_chosen = result[choice]
- -- textDocument/codeAction can return either Command[] or CodeAction[].
- -- If it is a CodeAction, it can have either an edit, a command or both.
- -- Edits should be executed first
- if action_chosen.edit or type(action_chosen.command) == "table" then
- if action_chosen.edit then
- util.apply_workspace_edit(action_chosen.edit)
- end
- if type(action_chosen.command) == "table" then
- buf.execute_command(action_chosen.command)
- end
+ local action = result[choice]
+ -- textDocument/codeAction can return either Command[] or CodeAction[]
+ --
+ -- CodeAction
+ -- ...
+ -- edit?: WorkspaceEdit -- <- must be applied before command
+ -- command?: Command
+ --
+ -- Command:
+ -- title: string
+ -- command: string
+ -- arguments?: any[]
+ --
+ if action.edit then
+ util.apply_workspace_edit(action.edit)
+ end
+ local command = type(action.command) == 'table' and action.command or action
+ local fn = vim.lsp.commands[command.command]
+ if fn then
+ fn(command, ctx)
else
- buf.execute_command(action_chosen)
+ buf.execute_command(command)
end
end