LSP: Handle rpc RequestCancelled specifically. (#11606)

This was creating extra noise in errors that we should've been handling
internally.

Fixes #11515
This commit is contained in:
Ashkan Kiani 2019-12-24 14:28:09 -08:00 committed by GitHub
parent 34abe8fd23
commit 07a2260e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
local vim = vim
local uv = vim.loop
local log = require('vim.lsp.log')
local protocol = require('vim.lsp.protocol')
@ -377,6 +378,22 @@ local function create_and_start_client(cmd, cmd_args, handlers, extra_spawn_para
decoded.error = convert_NIL(decoded.error)
decoded.result = convert_NIL(decoded.result)
-- Do not surface RequestCancelled to users, it is RPC-internal.
if decoded.error
and decoded.error.code == protocol.ErrorCodes.RequestCancelled then
local _ = log.debug() and log.debug("Received cancellation ack", decoded)
local result_id = tonumber(decoded.id)
-- Clear any callback since this is cancelled now.
-- This is safe to do assuming that these conditions hold:
-- - The server will not send a result callback after this cancellation.
-- - If the server sent this cancellation ACK after sending the result, the user of this RPC
-- client will ignore the result themselves.
if result_id then
message_callbacks[result_id] = nil
end
return
end
-- We sent a number, so we expect a number.
local result_id = tonumber(decoded.id)
local callback = message_callbacks[result_id]