diff options
author | Mathias Fussenegger <f.mathias@zignar.net> | 2021-03-12 10:19:21 +0100 |
---|---|---|
committer | Mathias Fussenegger <f.mathias@zignar.net> | 2021-09-20 22:26:00 +0200 |
commit | 6c03601e3adb4c3c4d47f148df8df20401b88677 (patch) | |
tree | 8557c570d06fde14eeb25c97a320c1a86f979b13 /runtime/lua/vim/lsp.lua | |
parent | 187579fe197ddd844bc0b0979e7f53c646f4235e (diff) | |
download | rneovim-6c03601e3adb4c3c4d47f148df8df20401b88677.tar.gz rneovim-6c03601e3adb4c3c4d47f148df8df20401b88677.tar.bz2 rneovim-6c03601e3adb4c3c4d47f148df8df20401b88677.zip |
feat(lsp): add a registry for client side code action commands
This builds on https://github.com/neovim/neovim/pull/14112 and closes
https://github.com/neovim/neovim/issues/12326
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r-- | runtime/lua/vim/lsp.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 17ba4939bd..ae9a7ab513 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -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 |