mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
lsp: do not assert even if the code does not exist in ErrorCodes (#11981)
There is ErrorCodes in the LSP specification, but in ResponseError.code it is not used and the actual type is number. Some language servers response original error cods and this is valid spec. So we shouldn't assert even if the code does not exist in ErrorCodes. ref: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#responseMessage
This commit is contained in:
@@ -140,14 +140,23 @@ local function format_rpc_error(err)
|
||||
validate {
|
||||
err = { err, 't' };
|
||||
}
|
||||
local code_name = assert(protocol.ErrorCodes[err.code], "err.code is invalid")
|
||||
local message_parts = {"RPC", code_name}
|
||||
|
||||
-- There is ErrorCodes in the LSP specification,
|
||||
-- but in ResponseError.code it is not used and the actual type is number.
|
||||
local code
|
||||
if protocol.ErrorCodes[err.code] then
|
||||
code = string.format("code_name = %s,", protocol.ErrorCodes[err.code])
|
||||
else
|
||||
code = string.format("code_name = unknown, code = %s,", err.code)
|
||||
end
|
||||
|
||||
local message_parts = {"RPC[Error]", code}
|
||||
if err.message then
|
||||
table.insert(message_parts, "message = ")
|
||||
table.insert(message_parts, "message =")
|
||||
table.insert(message_parts, string.format("%q", err.message))
|
||||
end
|
||||
if err.data then
|
||||
table.insert(message_parts, "data = ")
|
||||
table.insert(message_parts, "data =")
|
||||
table.insert(message_parts, vim.inspect(err.data))
|
||||
end
|
||||
return table.concat(message_parts, ' ')
|
||||
|
Reference in New Issue
Block a user