mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
feat(lsp): fallback to code-action command on resolve failure
This commit is contained in:
@@ -679,7 +679,7 @@ local function on_code_action_results(results, ctx, options)
|
|||||||
-- command: string
|
-- command: string
|
||||||
-- arguments?: any[]
|
-- arguments?: any[]
|
||||||
--
|
--
|
||||||
local client = vim.lsp.get_client_by_id(action_tuple[1])
|
local client = assert(vim.lsp.get_client_by_id(action_tuple[1]))
|
||||||
local action = action_tuple[2]
|
local action = action_tuple[2]
|
||||||
if
|
if
|
||||||
not action.edit
|
not action.edit
|
||||||
@@ -688,10 +688,14 @@ local function on_code_action_results(results, ctx, options)
|
|||||||
then
|
then
|
||||||
client.request('codeAction/resolve', action, function(err, resolved_action)
|
client.request('codeAction/resolve', action, function(err, resolved_action)
|
||||||
if err then
|
if err then
|
||||||
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
|
if action.command then
|
||||||
return
|
apply_action(action, client)
|
||||||
|
else
|
||||||
|
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
apply_action(resolved_action, client)
|
||||||
end
|
end
|
||||||
apply_action(resolved_action, client)
|
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
apply_action(action, client)
|
apply_action(action, client)
|
||||||
|
@@ -3309,6 +3309,48 @@ describe('LSP', function()
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
it("Fallback to command execution on resolve error", function()
|
||||||
|
clear()
|
||||||
|
exec_lua(create_server_definition)
|
||||||
|
local result = exec_lua([[
|
||||||
|
local server = _create_server({
|
||||||
|
capabilities = {
|
||||||
|
executeCommandProvider = {
|
||||||
|
commands = {"command:1"},
|
||||||
|
},
|
||||||
|
codeActionProvider = {
|
||||||
|
resolveProvider = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handlers = {
|
||||||
|
["textDocument/codeAction"] = function()
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
title = "Code Action 1",
|
||||||
|
command = {
|
||||||
|
title = "Command 1",
|
||||||
|
command = "command:1",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
["codeAction/resolve"] = function()
|
||||||
|
return nil, "resolve failed"
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
local client_id = vim.lsp.start({
|
||||||
|
name = "dummy",
|
||||||
|
cmd = server.cmd,
|
||||||
|
})
|
||||||
|
vim.lsp.buf.code_action({ apply = true })
|
||||||
|
vim.lsp.stop_client(client_id)
|
||||||
|
return server.messages
|
||||||
|
]])
|
||||||
|
eq("codeAction/resolve", result[4].method)
|
||||||
|
eq("workspace/executeCommand", result[5].method)
|
||||||
|
eq("command:1", result[5].params.command)
|
||||||
|
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