aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
diff options
context:
space:
mode:
authorMathias Fussenegger <f.mathias@zignar.net>2021-07-11 11:22:35 +0200
committerMathias Fussenegger <f.mathias@zignar.net>2021-07-11 11:22:35 +0200
commitc21a6972a02c00a5d809051c6300eed351fb3b49 (patch)
treefdab9726e8e7abe5054f8ba6d3a1e237de840bf6 /runtime/lua/vim/lsp/handlers.lua
parent256570a7a628aa377f405cb55343a38d186dc770 (diff)
downloadrneovim-c21a6972a02c00a5d809051c6300eed351fb3b49.tar.gz
rneovim-c21a6972a02c00a5d809051c6300eed351fb3b49.tar.bz2
rneovim-c21a6972a02c00a5d809051c6300eed351fb3b49.zip
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.lua22
1 files changed, 10 insertions, 12 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 4680f2e9de..4c7cb28871 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
@@ -454,7 +447,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)