mirror of
https://github.com/neovim/neovim
synced 2025-07-24 15:21:53 +00:00
fix(lsp): fix multi client handling in code action (#18869)
Fixes https://github.com/neovim/neovim/issues/18860
(cherry picked from commit e4df1c9b9e
)
This commit is contained in:
@ -516,7 +516,14 @@ local function on_code_action_results(results, ctx)
|
|||||||
enriched_ctx.client_id = client.id
|
enriched_ctx.client_id = client.id
|
||||||
fn(command, enriched_ctx)
|
fn(command, enriched_ctx)
|
||||||
else
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -673,6 +673,34 @@ function tests.code_action_with_resolve()
|
|||||||
}
|
}
|
||||||
end
|
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.clientside_commands()
|
function tests.clientside_commands()
|
||||||
skeleton {
|
skeleton {
|
||||||
on_init = function()
|
on_init = function()
|
||||||
|
@ -2665,6 +2665,45 @@ describe('LSP', function()
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
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)
|
||||||
end)
|
end)
|
||||||
describe('vim.lsp.commands', function()
|
describe('vim.lsp.commands', function()
|
||||||
it('Accepts only string keys', function()
|
it('Accepts only string keys', function()
|
||||||
|
Reference in New Issue
Block a user