folke / todo-comments.nvim

✅ Highlight, list and search todo comments in your projects
Apache License 2.0
3.06k stars 88 forks source link

Counter in statusline #172

Closed RAprogramm closed 1 year ago

RAprogramm commented 1 year ago

Anybody have idea how to realize counter in lualine?

IlyasYOY commented 1 year ago

Hello @RAprogramm

I assume that you can reuse this function.

RAprogramm commented 1 year ago

Easier say than done. At real time I nave not enough knowledge and skills to do that. In my head only - if TODO then count++. I don't want to make same function as we have in this plugin (because it will be duplicate of code I think) . I want to know how to get a count of already we have a list of todos

folke commented 1 year ago

I you want to add that to the statusline, then you'll need to create a function that properly throttles those calls. You don't wan to do those searches 100s of times per second (redraw of statusline).

As suggested, you can use that search function for that, but the implementation is on you.

RAprogramm commented 1 year ago
local function count()
  return require('todo-comments.search').search(
    function(results) print(#results) end
  )
end

print(count())

this will print number of todos.

but this

local function count()
  return require('todo-comments.search').search(
    function(results) return #results end
  )
end

print(count())

will return nothing! why? i need this number and it will done. what is my problem?

folke commented 1 year ago

That function is asynchronous, so it doesn't work like that