Open crides opened 1 year ago
Although an API for this explicit purpose is missing, you can still write your own statusline component generating function using require('todo-comments.search').search()
, as mentioned in #172.
As @folke has mentioned in that same thread, you need to properly throttle this function so it does not slow down the UI.
I have written a primitive implementation for the same purpose, but never got around to throttling it for performance since it is working well enough for me (for now). You can adapt it for your case if you wish, I will update it for throttling when I find the time.
You can find the function statusline_todo_list()
here (on line 92 at time of writing).
Thanks. I'll look into this when I got more time
Although an API for this explicit purpose is missing, you can still write your own statusline component generating function using
require('todo-comments.search').search()
, as mentioned in #172. As @folke has mentioned in that same thread, you need to properly throttle this function so it does not slow down the UI.I have written a primitive implementation for the same purpose, but never got around to throttling it for performance since it is working well enough for me (for now). You can adapt it for your case if you wish, I will update it for throttling when I find the time. You can find the function
statusline_todo_list()
here (on line 92 at time of writing).
Hi. I'm interested in that function and the link does not work. Would you mind if you can share the function?
Sorry about that, here you go! :)
local todo = {
---@type table<string,string> map of TODO keywords and their icons
render = {
FIX = '',
HACK = '',
NOTE = '',
PERF = '',
TEST = '✎',
TODO = '',
WARN = '',
},
---@type table<string, integer> map of TODO keywords and their counts
stats = {},
}
---returns a highlight-supported string of TODO comment statistics
-- PERF: expensive function, proper throttling required
-- [ Check https://github.com/folke/todo-comments.nvim/issues/172#issuecomment-1382691260 ]
function status.statusline_todo_list()
if not require('todo-comments.config').loaded then return '' end
-- count number of keyword occurences
require('todo-comments.search').search(function(entries)
todo.stats = {}
for _, entry in ipairs(entries) do
todo.stats[entry.tag] = (todo.stats[entry.tag] or 0) + 1
end
end, { disable_not_found_warnings = true })
local out = {}
for keyword, count in vim.spairs(todo.stats) do
table.insert(out, ('%%#TodoFg%s#%s %d '):format(keyword, todo.render[keyword], count))
end
if not vim.tbl_isempty(out) then
table.insert(out, 1, '%#TabLineSel#◤◢%* ')
table.insert(out, '%#TabLineSel#◤◢%*')
end
return table.concat(out)
end
There are a bunch of config-specific things here and there, but you should be able to adapt it to your tastes.
thanks!
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
I would like this feature.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Did you check the docs?
Is your feature request related to a problem? Please describe.
Not possible yet to have the todo counts on the statusline
Describe the solution you'd like
some api functions are provided to fetch the type, icon, and count of todos in a buffer
Describe alternatives you've considered
can't really think of other good alternatives now; relying on loclist/telescope intermediate commands seems pretty janky
Additional context
No response