diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/fixtures/fake-lsp-server.lua | 30 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 36 |
2 files changed, 66 insertions, 0 deletions
diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index 7ff3713d41..3375a5dda9 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -673,6 +673,36 @@ function tests.code_action_with_resolve() } end +function tests.code_action_filter() + skeleton { + on_init = function() + return { + capabilities = { + codeActionProvider = { + resolveProvider = false + } + } + } + end; + body = function() + notify('start') + local action = { + title = 'Action 1', + command = 'command' + } + local preferred_action = { + title = 'Action 2', + isPreferred = true, + command = 'preferred_command', + } + expect_request('textDocument/codeAction', function() + return nil, { action, preferred_action, } + end) + notify('shutdown') + end; + } +end + function tests.clientside_commands() skeleton { on_init = function() diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 436b431e38..03ed167bac 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2665,6 +2665,42 @@ describe('LSP', function() end } end) + it('Filters and automatically applies action if requested', function() + local client + local expected_handlers = { + {NIL, {}, {method="shutdown", client_id=1}}; + {NIL, {}, {method="start", client_id=1}}; + } + test_rpc_server { + test_name = 'code_action_filter', + on_init = function(client_) + client = client_ + end, + on_setup = function() + end, + on_exit = function(code, signal) + eq(0, code, "exit code", fake_lsp_logfile) + eq(0, signal, "exit signal", fake_lsp_logfile) + end, + on_handler = function(err, result, ctx) + eq(table.remove(expected_handlers), {err, result, ctx}) + if ctx.method == 'start' then + exec_lua([[ + vim.lsp.commands['preferred_command'] = function(cmd) + vim.lsp.commands['executed_preferred'] = 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, }) + ]]) + elseif ctx.method == 'shutdown' then + eq('function', exec_lua[[return type(vim.lsp.commands['executed_preferred'])]]) + client.stop() + end + end + } + end) end) describe('vim.lsp.commands', function() it('Accepts only string keys', function() |