Skip to content

Commit

Permalink
[enhance]: enhance error handle
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Feb 2, 2024
1 parent f7bd0a4 commit d1fcd3d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
30 changes: 22 additions & 8 deletions lua/LspUI/hover/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ M.get_hovers = function(clients, buffer_id, callback)
local params = lsp.util.make_position_params()
local tmp_number = 0

--- @type string[]
--- @type {name:string, err:lsp.ResponseError}[]
local invalid_clients = {}

for _, client in pairs(clients) do
Expand All @@ -42,12 +42,15 @@ M.get_hovers = function(clients, buffer_id, callback)
params,
---@param result lsp.Hover
---@param lsp_config any
function(_, result, _, lsp_config)
function(err, result, _, lsp_config)
lsp_config = lsp_config or {}

if not (result and result.contents) then
if err ~= nil then
if lsp_config.silent ~= true then
table.insert(invalid_clients, client.name)
table.insert(
invalid_clients,
{ name = client.name, err = err }
)
end
else
local markdown_lines =
Expand Down Expand Up @@ -124,12 +127,23 @@ M.get_hovers = function(clients, buffer_id, callback)
if tmp_number == #clients then
if not vim.tbl_isempty(invalid_clients) then
local names = ""
for index, client_name in pairs(invalid_clients) do
if index == 1 then
names = names .. client_name
for index, val in pairs(invalid_clients) do
if index == #invalid_clients then
names = names
.. string.format(
"server %s, err code is %d, err code is %s",
val.name,
val.err.code,
val.err.message
)
else
names = names
.. string.format(", %s", client_name)
.. string.format(
"server %s, err code is %d, err code is %s, ",
val.name,
val.err.code,
val.err.message
)
end
end
lib_notify.Info(
Expand Down
2 changes: 2 additions & 0 deletions lua/LspUI/lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ M.debounce = function(func, delay)
local args = { ... }
if timer then
timer:stop()
timer:close()
timer = nil
end

Expand Down Expand Up @@ -161,6 +162,7 @@ M.get_uri_lines = function(buffer_id, uri, rows)
local found = 0
local lnum = 0

---@diagnostic disable-next-line: param-type-mismatch
for line in string.gmatch(data, "([^\n]*)\n?") do
if lines[lnum] == true then
lines[lnum] = line
Expand Down
25 changes: 21 additions & 4 deletions lua/LspUI/lightbulb/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local code_action_register = require("LspUI.code_action.register")
local config = require("LspUI.config")
local global = require("LspUI.global")
local lib_lsp = require("LspUI.lib.lsp")
local lib_notify = require("LspUI.lib.notify")
local lib_util = require("LspUI.lib.util")

local M = {}
Expand Down Expand Up @@ -120,12 +121,28 @@ M.request = function(buffer_id, callback)
local clients = M.get_clients(buffer_id)
local tmp_number = 0
for _, client in pairs(clients or {}) do
client.request(code_action_feature, params, function(_, result, _, _)
client.request(code_action_feature, params, function(err, result, _, _)
tmp_number = tmp_number + 1
if result and type(result) == "table" and next(result) ~= nil then
new_callback(true)
return
if err ~= nil then
lib_notify.Warn(
string.format(
"lightbulb meet error, server %s, error code is %d, msg is %s",
client.name,
err.code,
err.message
)
)
else
if
result
and type(result) == "table"
and next(result) ~= nil
then
new_callback(true)
return
end
end

if tmp_number == #clients then
new_callback(false)
end
Expand Down
7 changes: 6 additions & 1 deletion lua/LspUI/pos_abstract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,12 @@ M.lsp_clients_request = function(buffer_id, clients, params, callback)

if err ~= nil then
lib_notify.Warn(
string.format("when %s, err: %s", method.name, err)
string.format(
"method %s meet error, error code is %d, msg is %s",
method.name,
err.code,
err.message
)
)
else
if result and not vim.tbl_isempty(result) then
Expand Down

0 comments on commit d1fcd3d

Please sign in to comment.