diff options
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 9 | ||||
-rw-r--r-- | test/functional/fixtures/fake-lsp-server.lua | 29 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 39 |
3 files changed, 76 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index 0b2e1c9b8d..fa8ee23805 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -752,7 +752,14 @@ local function on_code_action_results(results, ctx, options) enriched_ctx.client_id = client.id fn(command, enriched_ctx) else - M.execute_command(command) + -- Not using command directly to exclude extra properties, + -- see https://github.com/python-lsp/python-lsp-server/issues/146 + local params = { + command = command.command, + arguments = command.arguments, + workDoneToken = command.workDoneToken, + } + client.request('workspace/executeCommand', params, nil, ctx.bufnr) end end end diff --git a/test/functional/fixtures/fake-lsp-server.lua b/test/functional/fixtures/fake-lsp-server.lua index 9bceb612a5..0dc0c8c2db 100644 --- a/test/functional/fixtures/fake-lsp-server.lua +++ b/test/functional/fixtures/fake-lsp-server.lua @@ -757,6 +757,35 @@ function tests.code_action_with_resolve() } end +function tests.code_action_server_side_command() + skeleton({ + on_init = function() + return { + capabilities = { + codeActionProvider = { + resolveProvider = false, + }, + }, + } + end, + body = function() + notify('start') + local cmd = { + title = 'Command 1', + command = 'dummy1', + } + expect_request('textDocument/codeAction', function() + return nil, { cmd } + end) + expect_request('workspace/executeCommand', function() + return nil, cmd + end) + notify('shutdown') + end, + }) +end + + function tests.code_action_filter() skeleton { on_init = function() diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index 05ea6f7523..22e2354723 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -2793,6 +2793,45 @@ describe('LSP', function() end } end) + it('Calls workspace/executeCommand if no client side command', function() + local client + local expected_handlers = { + { NIL, {}, { method = 'shutdown', client_id = 1 } }, + { + NIL, + { command = 'dummy1', title = 'Command 1' }, + { bufnr = 1, method = 'workspace/executeCommand', client_id = 1 }, + }, + { NIL, {}, { method = 'start', client_id = 1 } }, + } + test_rpc_server({ + test_name = 'code_action_server_side_command', + 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) + ctx.params = nil -- don't compare in assert + eq(table.remove(expected_handlers), { err, result, ctx }) + if ctx.method == 'start' then + exec_lua([[ + local bufnr = vim.api.nvim_get_current_buf() + vim.lsp.buf_attach_client(bufnr, TEST_RPC_CLIENT_ID) + vim.fn.inputlist = function() + return 1 + end + vim.lsp.buf.code_action() + ]]) + elseif ctx.method == 'shutdown' then + client.stop() + end + end, + }) + end) it('Filters and automatically applies action if requested', function() local client local expected_handlers = { |