Skip to content

Commit

Permalink
feat: add telescope integration
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyonn committed Jan 20, 2025
1 parent a0abbf1 commit 0e41de5
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/fidget.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,20 @@ those highlight groups.
You can override these highlight groups (e.g., `icon_style`) using the
|fidget-options| shown above.

==============================================================================
6. Telescope *fidget-telescope*

Fidget is bundled with a telescope picker extension, the picker will show all
history notifications, same as `Fidget history`. To enable it, add the
following to your config.
>lua
require("telescope").load_extension("fidget")
<

Use command `:Telescope fidget` or lua api `lua require("telescope").extensions.fidget.fidget()`

==============================================================================
6. Related Work *fidget-related-work*
7. Related Work *fidget-related-work*

rcarriga/nvim-notify <https://github.com/rcarriga/nvim-notify> is first and
foremost a `vim.notify()` backend, and it also supports LSP progress
Expand Down
93 changes: 93 additions & 0 deletions lua/telescope/_extensions/fidget.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
local actions = require("telescope.actions")
local conf = require("telescope.config").values
local entry_display = require("telescope.pickers.entry_display")
local finders = require("telescope.finders")
local notification = require("fidget.notification")
local pickers = require("telescope.pickers")
local telescope = require("telescope")

local fidget_picker = function(opts)
opts = opts or {}

local displayer = entry_display.create({
separator = " ",
items = {
{},
{},
{},
{ width = 4 },
{ remaining = true },
},
})

pickers
.new(opts, {
prompt_title = "Notifications",
finder = finders.new_table({
results = notification.get_history(),
entry_maker = function(entry)
return {
value = entry,
display = function()
local chunks = {}

table.insert(
chunks,
{ vim.fn.strftime("%c", entry.last_updated), "Comment" }
)

if entry.group_name and #entry.group_name > 0 then
table.insert(chunks, { entry.group_name, "Special" })
else
table.insert(chunks, { " ", "MsgArea" })
end

table.insert(chunks, { " | ", "Comment" })

if entry.annote and #entry.annote > 0 then
table.insert(chunks, { entry.annote, entry.style })
else
table.insert(chunks, { " ", "MsgArea" })
end

table.insert(chunks, { entry.message, "MsgArea" })

return displayer(chunks)
end,
ordinal = entry.message,
}
end,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, _)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
end)

actions.select_horizontal:replace(function()
actions.close(prompt_bufnr)
end)

actions.select_vertical:replace(function()
actions.close(prompt_bufnr)
end)

actions.select_tab:replace(function()
actions.close(prompt_bufnr)
end)

return true
end,
})
:find()
end

return telescope.register_extension({
setup = function() end,

exports = {
fidget = function(opts)
fidget_picker(opts)
end,
},
})

0 comments on commit 0e41de5

Please sign in to comment.