fix(lsp): perform client side filtering of code actions (#18392)

Implement filtering of actions based on the kind when passing the 'only'
parameter to code_action(). Action kinds are hierachical with a '.' as
the separator, and the filter thus allows, for example, both 'quickfix'
and 'quickfix.foo' when requestiong only 'quickfix'.

Fix https://github.com/neovim/neovim/pull/18221#issuecomment-1110179121
This commit is contained in:
Fredrik Ekre
2022-05-12 18:48:02 +02:00
committed by GitHub
parent de5ccf2348
commit a9d25e9472
3 changed files with 65 additions and 3 deletions

View File

@@ -2753,12 +2753,33 @@ describe('LSP', function()
vim.lsp.commands['executed_preferred'] = function()
end
end
vim.lsp.commands['quickfix_command'] = function(cmd)
vim.lsp.commands['executed_quickfix'] = function()
end
end
local bufnr = vim.api.nvim_get_current_buf()
vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID)
vim.lsp.buf.code_action({ filter = function(a) return a.isPreferred end, apply = true, })
vim.lsp.buf.code_action({
-- expect to be returned actions 'quickfix' and 'quickfix.foo'
context = { only = {'quickfix'}, },
apply = true,
filter = function(a)
if a.kind == 'quickfix.foo' then
vim.lsp.commands['filtered_quickfix_foo'] = function() end
return false
elseif a.kind == 'quickfix' then
return true
else
assert(nil, 'unreachable')
end
end,
})
]])
elseif ctx.method == 'shutdown' then
eq('function', exec_lua[[return type(vim.lsp.commands['executed_preferred'])]])
eq('function', exec_lua[[return type(vim.lsp.commands['filtered_quickfix_foo'])]])
eq('function', exec_lua[[return type(vim.lsp.commands['executed_quickfix'])]])
client.stop()
end
end