feat(lsp): pass client ID in code action filter (#36046)

This commit is contained in:
Maria Solano
2025-10-05 15:02:00 -07:00
committed by GitHub
parent bcc9242bc7
commit 729e0acd26
3 changed files with 12 additions and 7 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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