Skip to content

Commit

Permalink
feat: use 'pcall' on configured 'format' function (#66)
Browse files Browse the repository at this point in the history
* feat: use pcall on configured 'format'

* test case
  • Loading branch information
linrongbin16 authored Oct 2, 2023
1 parent 0655d95 commit d647a46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lua/lsp-progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,15 @@ local function progress(option)
)
end
end
local content = option.format(client_messages)
local ok, result = pcall(option.format, client_messages)
if not ok then
logger.err(
"failed to invoke 'format' function! error: %s, params: %s",
vim.inspect(result),
vim.inspect(client_messages)
)
end
local content = result
-- logger.debug(
-- "|lsp-progress.progress| Progress format: %s",
-- vim.inspect(content)
Expand Down Expand Up @@ -323,4 +331,4 @@ local M = {
progress = progress,
}

return M
return M
18 changes: 18 additions & 0 deletions tests/minimal_neodev_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ local plugins = {
function()
return require("lsp-progress").progress({
max_size = 80,
format = function(messages)
local active_clients =
vim.lsp.get_active_clients()
if #messages > 0 then
return table.concat(messages, " ")
end
local client_names = {}
for _, client in ipairs(active_clients) do
if client and client.name ~= "" then
table.insert(
client_names,
1,
client.name
)
end
end
return table.concat(client_names, "")
end,
})
end,
icon = { "", align = "right" },
Expand Down

0 comments on commit d647a46

Please sign in to comment.