Change error writer to not be annoying.

This commit is contained in:
Ashkan Kiani
2019-11-20 16:16:13 -08:00
parent 03eb88848c
commit c40f8600d2
2 changed files with 14 additions and 5 deletions

View File

@@ -27,6 +27,11 @@ local lsp = {
-- TODO consider whether 'eol' or 'fixeol' should change the nvim_buf_get_lines that send. -- TODO consider whether 'eol' or 'fixeol' should change the nvim_buf_get_lines that send.
-- TODO improve handling of scratch buffers with LSP attached. -- TODO improve handling of scratch buffers with LSP attached.
local function err_message(...)
nvim_err_writeln(table.concat(vim.tbl_flatten{...}))
nvim_command("redraw")
end
local function resolve_bufnr(bufnr) local function resolve_bufnr(bufnr)
validate { bufnr = { bufnr, 'n', true } } validate { bufnr = { bufnr, 'n', true } }
if bufnr == nil or bufnr == 0 then if bufnr == nil or bufnr == 0 then
@@ -316,13 +321,12 @@ function lsp.start_client(config)
function handlers.on_error(code, err) function handlers.on_error(code, err)
local _ = log.error() and log.error(log_prefix, "on_error", { code = lsp.client_errors[code], err = err }) local _ = log.error() and log.error(log_prefix, "on_error", { code = lsp.client_errors[code], err = err })
print(string.format('%s: Error %s: %q', log_prefix, lsp.client_errors[code], vim.inspect(err))) err_message(log_prefix, ': Error ', lsp.client_errors[code], ': ', vim.inspect(err))
-- nvim_err_writeln(string.format('%s: Error %s: %q', log_prefix, lsp.client_errors[code], vim.inspect(err)))
if config.on_error then if config.on_error then
local status, usererr = pcall(config.on_error, code, err) local status, usererr = pcall(config.on_error, code, err)
if not status then if not status then
local _ = log.error() and log.error(log_prefix, "user on_error failed", { err = usererr }) local _ = log.error() and log.error(log_prefix, "user on_error failed", { err = usererr })
nvim_err_writeln(log_prefix.." user on_error failed: "..tostring(usererr)) err_message(log_prefix, ' user on_error failed: ', tostring(usererr))
end end
end end
end end
@@ -434,7 +438,7 @@ function lsp.start_client(config)
local function unsupported_method(method) local function unsupported_method(method)
local msg = "server doesn't support "..method local msg = "server doesn't support "..method
local _ = log.warn() and log.warn(msg) local _ = log.warn() and log.warn(msg)
nvim_err_writeln(msg) err_message(msg)
return lsp.rpc_response_error(protocol.ErrorCodes.MethodNotFound, msg) return lsp.rpc_response_error(protocol.ErrorCodes.MethodNotFound, msg)
end end

View File

@@ -23,6 +23,11 @@ local function npcall(fn, ...)
return ok_or_nil(pcall(fn, ...)) return ok_or_nil(pcall(fn, ...))
end end
local function err_message(...)
api.nvim_err_writeln(table.concat(vim.tbl_flatten{...}))
api.nvim_command("redraw")
end
local function find_window_by_var(name, value) local function find_window_by_var(name, value)
for _, win in ipairs(api.nvim_list_wins()) do for _, win in ipairs(api.nvim_list_wins()) do
if npcall(api.nvim_win_get_var, win, name) == value then if npcall(api.nvim_win_get_var, win, name) == value then
@@ -133,7 +138,7 @@ local function handle_location(result)
result = result[1] result = result[1]
end end
if result.uri == nil then if result.uri == nil then
api.nvim_err_writeln('[LSP] Could not find a valid location') err_message('[LSP] Could not find a valid location')
return return
end end
local result_file = vim.uri_to_fname(result.uri) local result_file = vim.uri_to_fname(result.uri)