Skip to content

Commit

Permalink
feat: ignore messages via to filter functions
Browse files Browse the repository at this point in the history
Previously, messages could only be ignored according to the name of the
LSP server they come from. (Prior to the legacy rewrite, this feature
was part of the user-specified render function. Kind of ugly how that
worked.)

This feature allows messages to be ignored according to logic in
arbitrary user-specified functions.

The slightly yucky thing about this design is that the "shape" of the
message object is not really well-specified or documented. For example,
it is not obvious why we need to check `msg.title` rather than anything
else. The example should be good enough though, at least for now.

Addresses #249
  • Loading branch information
j-hui committed Jul 7, 2024
1 parent 012a6a7 commit a01443a
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions lua/fidget/progress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,28 @@ progress.options = {
return client and client.name or nil
end,

--- List of LSP servers to ignore
--- List of filters to ignore LSP progress messages
---
--- Each filter is either a string or a function.
---
--- If it is a string, then it is treated as the name of a LSP server;
--- messages from that server are ignored.
---
--- If it is a function, then the progress message object is passed to the
--- function. If the function returns a truthy value, then that message is
--- ignored.
---
--- Example:
--->lua
--- ignore = { "rust_analyzer" }
--- ignore = {
--- "rust_analyzer", -- Ignore all messages from rust-analyzer
--- function(msg) -- Ignore messages containing "ing"
--- return string.find(msg.title, "ing") ~= nil
--- end,
--- }
---<
---
---@type Key[]
---@type (string|fun(msg: ProgressMessage): any)[]
ignore = {},

display = progress.display,
Expand Down Expand Up @@ -214,13 +228,21 @@ progress.poller = poll.Poller {
for _, msg in ipairs(messages) do
-- Determine if we should ignore this message
local ignore = false
for _, lsp_name in ipairs(progress.options.ignore) do
-- NOTE: hopefully this loop isn't too expensive.
-- But if it is, consider indexing by hash.
if msg.lsp_client.name == lsp_name then
ignore = true
logger.info("Ignoring LSP progress message from", lsp_name, ":", msg)
break
for _, filter in ipairs(progress.options.ignore) do
if type(filter) == "string" then
if msg.lsp_client.name == filter then
ignore = true
logger.info("Ignoring LSP progress message by name from", filter, ":", msg)
break
end
elseif type(filter) == "function" then
if filter(msg) then
ignore = true
logger.info("Filtering out LSP progress message", ":", msg)
break
end
else
logger.error("Unsupported filter type:", type(filter))
end
end
if not ignore then
Expand Down

0 comments on commit a01443a

Please sign in to comment.