aboutsummaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorFredrik Ekre <ekrefredrik@gmail.com>2022-05-12 18:48:02 +0200
committerGitHub <noreply@github.com>2022-05-12 18:48:02 +0200
commita9d25e94725d5cfc41c2fabff22b2284e109fa0c (patch)
tree1f7382012d1ecded52011e600c651c48e406bd77 /test/functional
parentde5ccf2348a1fabf3867da9256e4740a7dfcf004 (diff)
downloadrneovim-a9d25e94725d5cfc41c2fabff22b2284e109fa0c.tar.gz
rneovim-a9d25e94725d5cfc41c2fabff22b2284e109fa0c.tar.bz2
rneovim-a9d25e94725d5cfc41c2fabff22b2284e109fa0c.zip
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
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/fixtures/fake-lsp-server.lua15
-rw-r--r--test/functional/plugin/lsp_spec.lua21
2 files changed, 35 insertions, 1 deletions
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua
index f589f5955f..86cdf4ef56 100644
--- a/test/functional/fixtures/fake-lsp-server.lua
+++ b/test/functional/fixtures/fake-lsp-server.lua
@@ -766,8 +766,21 @@ function tests.code_action_filter()
isPreferred = true,
command = 'preferred_command',
}
+ local quickfix_action = {
+ title = 'Action 3',
+ kind = 'quickfix',
+ command = 'quickfix_command',
+ }
+ local quickfix_foo_action = {
+ title = 'Action 4',
+ kind = 'quickfix.foo',
+ command = 'quickfix_foo_command',
+ }
+ expect_request('textDocument/codeAction', function()
+ return nil, { action, preferred_action, quickfix_action, quickfix_foo_action, }
+ end)
expect_request('textDocument/codeAction', function()
- return nil, { action, preferred_action, }
+ return nil, { action, preferred_action, quickfix_action, quickfix_foo_action, }
end)
notify('shutdown')
end;
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index 33a8976b79..4cb7636825 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -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