diff options
author | Mathias Fussenegger <f.mathias@zignar.net> | 2021-07-11 11:22:35 +0200 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-09-16 14:37:20 +0100 |
commit | a265201307f6d7551518b67e16de68f5b9e2527c (patch) | |
tree | 08afdf6883e8256d37cb738ad2474047615c88c6 /runtime/lua/vim/lsp/handlers.lua | |
parent | 33000bd9cff3efe54c4ca14756008300d18ac07b (diff) | |
download | rneovim-a265201307f6d7551518b67e16de68f5b9e2527c.tar.gz rneovim-a265201307f6d7551518b67e16de68f5b9e2527c.tar.bz2 rneovim-a265201307f6d7551518b67e16de68f5b9e2527c.zip |
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.
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 4266134fe6..0c0aa0ceb6 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -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) |