mirror of
https://github.com/neovim/neovim.git
synced 2025-11-11 04:55:33 +00:00
lsp: Only mute RequestCancelled or ContentModified, but not other errors
handlers passed to `lsp_buf_request` weren't called if the server
responded with an error that looks like this:
"decoded", {
error = {
code = -32601,
message = "No delegateCommandHandler for foo"
},
id = 5,
jsonrpc = "2.0"
}
An example where that happens is both eclipse.jdt.ls and the
haskell-language-server when invoking a command that doesn't exist:
:lua vim.lsp.buf_request(
0,
'workspace/executeCommand',
{ command = 'foo' },
function(err, _, res)
print(vim.inspect(err), vim.inspect(res))
end
)
This commit is contained in:
@@ -523,14 +523,21 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
|
|||||||
decoded.error = convert_NIL(decoded.error)
|
decoded.error = convert_NIL(decoded.error)
|
||||||
decoded.result = convert_NIL(decoded.result)
|
decoded.result = convert_NIL(decoded.result)
|
||||||
|
|
||||||
|
-- We sent a number, so we expect a number.
|
||||||
|
local result_id = tonumber(decoded.id)
|
||||||
|
|
||||||
-- Do not surface RequestCancelled or ContentModified to users, it is RPC-internal.
|
-- Do not surface RequestCancelled or ContentModified to users, it is RPC-internal.
|
||||||
if decoded.error then
|
if decoded.error then
|
||||||
|
local mute_error = false
|
||||||
if decoded.error.code == protocol.ErrorCodes.RequestCancelled then
|
if decoded.error.code == protocol.ErrorCodes.RequestCancelled then
|
||||||
local _ = log.debug() and log.debug("Received cancellation ack", decoded)
|
local _ = log.debug() and log.debug("Received cancellation ack", decoded)
|
||||||
|
mute_error = true
|
||||||
elseif decoded.error.code == protocol.ErrorCodes.ContentModified then
|
elseif decoded.error.code == protocol.ErrorCodes.ContentModified then
|
||||||
local _ = log.debug() and log.debug("Received content modified ack", decoded)
|
local _ = log.debug() and log.debug("Received content modified ack", decoded)
|
||||||
|
mute_error = true
|
||||||
end
|
end
|
||||||
local result_id = tonumber(decoded.id)
|
|
||||||
|
if mute_error then
|
||||||
-- Clear any callback since this is cancelled now.
|
-- Clear any callback since this is cancelled now.
|
||||||
-- This is safe to do assuming that these conditions hold:
|
-- This is safe to do assuming that these conditions hold:
|
||||||
-- - The server will not send a result callback after this cancellation.
|
-- - The server will not send a result callback after this cancellation.
|
||||||
@@ -541,9 +548,8 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- We sent a number, so we expect a number.
|
|
||||||
local result_id = tonumber(decoded.id)
|
|
||||||
local callback = message_callbacks[result_id]
|
local callback = message_callbacks[result_id]
|
||||||
if callback then
|
if callback then
|
||||||
message_callbacks[result_id] = nil
|
message_callbacks[result_id] = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user