Skip to content

Commit

Permalink
feat: aggregate code actions from all clients (neovim#15121)
Browse files Browse the repository at this point in the history
  • Loading branch information
folke authored Jul 18, 2021
1 parent 5377b2b commit c36df20
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions runtime/lua/vim/lsp/buf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
--
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit c36df20

Please sign in to comment.