aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.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.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.lua')
-rw-r--r--runtime/lua/vim/lsp.lua31
1 files changed, 30 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 90c5872f11..ae9a7ab513 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -896,7 +896,7 @@ function lsp.start_client(config)
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, handler, bufnr)
return rpc.request(method, params, function(err, result)
- handler(err, result, {method=method, client_id=client_id, bufnr=bufnr})
+ handler(err, result, {method=method, client_id=client_id, bufnr=bufnr, params=params})
end)
end
@@ -1534,5 +1534,34 @@ function lsp._with_extend(name, options, user_config)
return resulting_config
end
+
+--- Registry for client side commands.
+--- This is an extension point for plugins to handle custom commands which are
+--- not part of the core language server protocol specification.
+---
+--- The registry is a table where the key is a unique command name,
+--- and the value is a function which is called if any LSP action
+--- (code action, code lenses, ...) triggers the command.
+---
+--- If a LSP response contains a command for which no matching entry is
+--- available in this registry, the command will be executed via the LSP server
+--- using `workspace/executeCommand`.
+---
+--- The first argument to the function will be the `Command`:
+-- Command
+-- title: String
+-- command: String
+-- arguments?: any[]
+--
+--- The second argument is the `ctx` of |lsp-handler|
+lsp.commands = setmetatable({}, {
+ __newindex = function(tbl, key, value)
+ assert(type(key) == 'string', "The key for commands in `vim.lsp.commands` must be a string")
+ assert(type(value) == 'function', "Command added to `vim.lsp.commands` must be a function")
+ rawset(tbl, key, value)
+ end;
+})
+
+
return lsp
-- vim:sw=2 ts=2 et