diff options
author | Folke Lemaitre <folke.lemaitre@gmail.com> | 2021-07-18 10:58:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-18 01:58:35 -0700 |
commit | c36df20aef22288f47e19084d2671327f7cd878c (patch) | |
tree | 8b0153131aa936b5df8b3da097fccd33aac55a61 /runtime/lua/vim/lsp/buf.lua | |
parent | 5377b2b00aea1a0bde1b81452e6198dabe5b9796 (diff) | |
download | rneovim-c36df20aef22288f47e19084d2671327f7cd878c.tar.gz rneovim-c36df20aef22288f47e19084d2671327f7cd878c.tar.bz2 rneovim-c36df20aef22288f47e19084d2671327f7cd878c.zip |
feat: aggregate code actions from all clients (#15121)
Diffstat (limited to 'runtime/lua/vim/lsp/buf.lua')
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index ced1747ee0..29f8d6c3bc 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -422,6 +422,21 @@ function M.clear_references() util.buf_clear_references() end +--- Requests code actions from all clients and calls the handler exactly once +--- with all aggregated results +--@private +local function code_action_request(params) + local bufnr = vim.api.nvim_get_current_buf() + local method = 'textDocument/codeAction' + vim.lsp.buf_request_all(bufnr, method, params, function(results) + local actions = {} + for _, r in pairs(results) do + vim.list_extend(actions, r.result or {}) + end + vim.lsp.handlers[method](nil, method, actions, nil, bufnr) + end) +end + --- Selects a code action from the input list that is available at the current --- cursor position. -- @@ -432,7 +447,7 @@ function M.code_action(context) context = context or { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() } local params = util.make_range_params() params.context = context - request('textDocument/codeAction', params) + code_action_request(params) end --- Performs |vim.lsp.buf.code_action()| for a given range. @@ -447,7 +462,7 @@ function M.range_code_action(context, start_pos, end_pos) context = context or { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() } local params = util.make_given_range_params(start_pos, end_pos) params.context = context - request('textDocument/codeAction', params) + code_action_request(params) end --- Executes an LSP server command. |