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`.
|
values like `refactor` or `quickfix`.
|
||||||
• {triggerKind}? (`integer`) The reason why code actions
|
• {triggerKind}? (`integer`) The reason why code actions
|
||||||
were requested.
|
were requested.
|
||||||
• {filter}? (`fun(x: lsp.CodeAction|lsp.Command):boolean`)
|
• {filter}?
|
||||||
Predicate taking an `CodeAction` and returning a boolean.
|
(`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
|
• {apply}? (`boolean`) When set to `true`, and there is just
|
||||||
one remaining action (after filtering), the action is
|
one remaining action (after filtering), the action is
|
||||||
applied without user query.
|
applied without user query.
|
||||||
|
@@ -252,6 +252,7 @@ LSP
|
|||||||
See |lsp-inline_completion| for quickstart instructions.
|
See |lsp-inline_completion| for quickstart instructions.
|
||||||
• Support for `textDocument/onTypeFormatting`: |lsp-on_type_formatting|
|
• Support for `textDocument/onTypeFormatting`: |lsp-on_type_formatting|
|
||||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_onTypeFormatting
|
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
|
LUA
|
||||||
|
|
||||||
|
@@ -1117,8 +1117,9 @@ end
|
|||||||
--- - {triggerKind}? (`integer`) The reason why code actions were requested.
|
--- - {triggerKind}? (`integer`) The reason why code actions were requested.
|
||||||
--- @field context? lsp.CodeActionContext
|
--- @field context? lsp.CodeActionContext
|
||||||
---
|
---
|
||||||
--- Predicate taking an `CodeAction` and returning a boolean.
|
--- Predicate taking a code action or command and the provider's ID.
|
||||||
--- @field filter? fun(x: lsp.CodeAction|lsp.Command):boolean
|
--- 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
|
--- When set to `true`, and there is just one remaining action
|
||||||
--- (after filtering), the action is applied without user query.
|
--- (after filtering), the action is applied without user query.
|
||||||
@@ -1142,7 +1143,8 @@ end
|
|||||||
---@param opts? vim.lsp.buf.code_action.Opts
|
---@param opts? vim.lsp.buf.code_action.Opts
|
||||||
local function on_code_action_results(results, opts)
|
local function on_code_action_results(results, opts)
|
||||||
---@param a lsp.Command|lsp.CodeAction
|
---@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
|
-- filter by specified action kind
|
||||||
if opts and opts.context then
|
if opts and opts.context then
|
||||||
if opts.context.only then
|
if opts.context.only then
|
||||||
@@ -1168,7 +1170,7 @@ local function on_code_action_results(results, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- filter by user function
|
-- 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
|
return false
|
||||||
end
|
end
|
||||||
-- no filter removed this action
|
-- no filter removed this action
|
||||||
@@ -1179,7 +1181,7 @@ local function on_code_action_results(results, opts)
|
|||||||
local actions = {}
|
local actions = {}
|
||||||
for _, result in pairs(results) do
|
for _, result in pairs(results) do
|
||||||
for _, action in pairs(result.result or {}) 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 })
|
table.insert(actions, { action = action, ctx = result.context })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user