mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
backport: fix(lsp): Ensure human readable errors are printed
`return err_message(tostring(err))` caused errors to be printed as `table: 0x123456789` instead of showing the error code and error message. This also removes some `if err` blocks that never got called because at the end of `handlers.lua` all the handlers are wrapped with logic that adds generic error handling.
This commit is contained in:
parent
33000bd9cf
commit
a265201307
@ -18,10 +18,8 @@ local function err_message(...)
|
||||
end
|
||||
|
||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
|
||||
M['workspace/executeCommand'] = function(err, _)
|
||||
if err then
|
||||
error("Could not execute code action: "..err.message)
|
||||
end
|
||||
M['workspace/executeCommand'] = function()
|
||||
-- Error handling is done implicitly by wrapping all handlers; see end of this file
|
||||
end
|
||||
|
||||
-- @msg of type ProgressParams
|
||||
@ -158,13 +156,12 @@ M['workspace/applyEdit'] = function(_, _, workspace_edit)
|
||||
end
|
||||
|
||||
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
|
||||
M['workspace/configuration'] = function(err, _, params, client_id)
|
||||
M['workspace/configuration'] = function(_, _, params, client_id)
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if not client then
|
||||
err_message("LSP[id=", client_id, "] client has shut down after sending the message")
|
||||
return
|
||||
end
|
||||
if err then error(vim.inspect(err)) end
|
||||
if not params.items then
|
||||
return {}
|
||||
end
|
||||
@ -199,11 +196,7 @@ end
|
||||
--@param map_result function `((resp, bufnr) -> list)` to convert the response
|
||||
--@param entity name of the resource used in a `not found` error message
|
||||
local function response_to_qflist(map_result, entity)
|
||||
return function(err, _, result, _, bufnr)
|
||||
if err then
|
||||
vim.notify(err.message, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
return function(_, _, result, _, bufnr)
|
||||
if not result or vim.tbl_isempty(result) then
|
||||
vim.notify('No ' .. entity .. ' found')
|
||||
else
|
||||
@ -443,7 +436,12 @@ for k, fn in pairs(M) do
|
||||
})
|
||||
|
||||
if err then
|
||||
return err_message(tostring(err))
|
||||
-- LSP spec:
|
||||
-- interface ResponseError:
|
||||
-- code: integer;
|
||||
-- message: string;
|
||||
-- data?: string | number | boolean | array | object | null;
|
||||
return err_message(tostring(err.code) .. ': ' .. err.message)
|
||||
end
|
||||
|
||||
return fn(err, method, params, client_id, bufnr, config)
|
||||
|
Loading…
Reference in New Issue
Block a user