mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 10:56:31 +00:00
feat(lsp): pass client ID in code action filter (#36046)
This commit is contained in:
@@ -1365,8 +1365,10 @@ code_action({opts}) *vim.lsp.buf.code_action()*
|
||||
values like `refactor` or `quickfix`.
|
||||
• {triggerKind}? (`integer`) The reason why code actions
|
||||
were requested.
|
||||
• {filter}? (`fun(x: lsp.CodeAction|lsp.Command):boolean`)
|
||||
Predicate taking an `CodeAction` and returning a boolean.
|
||||
• {filter}?
|
||||
(`fun(x: lsp.CodeAction|lsp.Command, client_id: integer):boolean`)
|
||||
Predicate taking a code action or command and the provider's
|
||||
ID. If it returns false, the action is filtered out.
|
||||
• {apply}? (`boolean`) When set to `true`, and there is just
|
||||
one remaining action (after filtering), the action is
|
||||
applied without user query.
|
||||
|
@@ -252,6 +252,7 @@ LSP
|
||||
See |lsp-inline_completion| for quickstart instructions.
|
||||
• Support for `textDocument/onTypeFormatting`: |lsp-on_type_formatting|
|
||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_onTypeFormatting
|
||||
• The filter option of |vim.lsp.buf.code_action()| now receives the client ID as an argument.
|
||||
|
||||
LUA
|
||||
|
||||
|
@@ -1117,8 +1117,9 @@ end
|
||||
--- - {triggerKind}? (`integer`) The reason why code actions were requested.
|
||||
--- @field context? lsp.CodeActionContext
|
||||
---
|
||||
--- Predicate taking an `CodeAction` and returning a boolean.
|
||||
--- @field filter? fun(x: lsp.CodeAction|lsp.Command):boolean
|
||||
--- Predicate taking a code action or command and the provider's ID.
|
||||
--- If it returns false, the action is filtered out.
|
||||
--- @field filter? fun(x: lsp.CodeAction|lsp.Command, client_id: integer):boolean
|
||||
---
|
||||
--- When set to `true`, and there is just one remaining action
|
||||
--- (after filtering), the action is applied without user query.
|
||||
@@ -1142,7 +1143,8 @@ end
|
||||
---@param opts? vim.lsp.buf.code_action.Opts
|
||||
local function on_code_action_results(results, opts)
|
||||
---@param a lsp.Command|lsp.CodeAction
|
||||
local function action_filter(a)
|
||||
---@param client_id integer
|
||||
local function action_filter(a, client_id)
|
||||
-- filter by specified action kind
|
||||
if opts and opts.context then
|
||||
if opts.context.only then
|
||||
@@ -1168,7 +1170,7 @@ local function on_code_action_results(results, opts)
|
||||
end
|
||||
end
|
||||
-- filter by user function
|
||||
if opts and opts.filter and not opts.filter(a) then
|
||||
if opts and opts.filter and not opts.filter(a, client_id) then
|
||||
return false
|
||||
end
|
||||
-- no filter removed this action
|
||||
@@ -1179,7 +1181,7 @@ local function on_code_action_results(results, opts)
|
||||
local actions = {}
|
||||
for _, result in pairs(results) do
|
||||
for _, action in pairs(result.result or {}) do
|
||||
if action_filter(action) then
|
||||
if action_filter(action, result.context.client_id) then
|
||||
table.insert(actions, { action = action, ctx = result.context })
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user