1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
-- notifications cache
_G.statusline_notifications = {}
_G.statusline_notifications_archive = {}
-- out vim.notify implementation
local notify = function(m, l, o)
local lvl_string = l
local hi = nil
if l and type(l) == 'number' then
if l == vim.log.levels.TRACE then
hi = 'deEmph'
elseif l == vim.log.levels.DEBUG then
hi = 'DiagnosticHint'
elseif l == vim.log.levels.INFO then
hi = 'DiagnosticInfo'
elseif l == vim.log.levels.WARN then
hi = 'DiagnosticWarn'
elseif l == vim.log.levels.ERROR then
hi = 'DiagnosticError'
end
-- get level string
lvl_string = vim.lsp.log_levels[l]
end
local display = m
if lvl_string then
display = lvl_string .. ' ' .. display
end
table.insert(_G.statusline_notifications, {
message = m,
level = l,
options = o,
lvl_string = lvl_string,
hi = hi,
display = display,
})
if _G.statusline_enable_notifysend then
local args = {}
if lvl_string then
if lvl_string == 'ERROR' then
table.insert(args, '--category=error')
end
if lvl_string == 'WARN' then
table.insert(args, '--category=warning')
end
end
table.insert(args, 'nvim')
table.insert(args, display)
require('internal.job').jobstart({ command = 'notify-send', args = args })
end
end
-- overwrite vim.notify
vim.notify = function(m, l, o)
if vim.in_fast_event() then
vim.schedule(function()
notify(m, l, o)
end)
else
return notify(m, l, o)
end
end
vim.keymap.set('n', '<leader>n', function()
local pickers = require('telescope.pickers')
local finders = require('telescope.finders')
local conf = require('telescope.config').values
local actions = require('telescope.actions')
-- local action_state = require('telescope.actions.state')
-- local previewers = require('telescope.previewers')
local opts = {}
pickers
.new(opts, {
prompt_title = 'Notifications',
finder = finders.new_dynamic({
fn = function()
return _G.statusline_notifications_archive
end,
entry_maker = function(n)
return {
value = n,
display = n.display,
ordinal = n.message,
}
end,
}),
sorter = conf.generic_sorter(opts),
attach_mappings = function(prompt_bufnr, _)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
-- noop
-- local sel = action_state.get_selected_entry()
-- vim.notify(sel.value.message, sel.value.level, sel.value.options)
end)
return true
end,
-- previewer = previewers.new_buffer_previewer {
-- define_preview = function(self, entry)
-- vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, {entry.value.display})
-- end,
-- },
})
:find()
end, { desc = 'notifications' })
|