Skip to content

Commit

Permalink
feat: added TodoLocList. Fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Aug 5, 2021
1 parent 4a27e05 commit c641728
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ This uses the quickfix list to show all todos in your project.

![image](https://user-images.githubusercontent.com/292349/118135332-bf9c2300-b3b7-11eb-9a40-1307feb27c44.png)

### 🔎 `:TodoLocList`

This uses the location list to show all todos in your project.

![image](https://user-images.githubusercontent.com/292349/118135332-bf9c2300-b3b7-11eb-9a40-1307feb27c44.png)

### 🚦 `:TodoTrouble`

List all project todos in [trouble](https://github.com/folke/trouble.nvim)
Expand Down
20 changes: 18 additions & 2 deletions lua/todo-comments/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ function M.search(cb, opts)
end

function M.setqflist(opts)
M.setlist(opts)
end

function M.setloclist(opts)
M.setlist(opts, true)
end

function M.setlist(opts, use_loclist)
if type(opts) == "string" then
opts = { cwd = opts }
if opts.cwd:sub(1, 4) == "cwd=" then
Expand All @@ -82,9 +90,17 @@ function M.setqflist(opts)
opts = opts or {}
opts.open = (opts.open ~= nil) and opts.open or true
M.search(function(results)
vim.fn.setqflist({}, " ", { title = "Todo", id = "$", items = results })
if use_loclist then
vim.fn.setloclist(0, {}, " ", { title = "Todo", id = "$", items = results })
else
vim.fn.setqflist({}, " ", { title = "Todo", id = "$", items = results })
end
if opts.open then
vim.cmd([[copen]])
if use_loclist then
vim.cmd([[lopen]])
else
vim.cmd([[copen]])
end
end
local win = vim.fn.getqflist({ winid = true })
if win.winid ~= 0 then
Expand Down
1 change: 1 addition & 0 deletions plugin/todo.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

command! -nargs=* TodoQuickFix lua require("todo-comments.search").setqflist(<f-args>)
command! -nargs=* TodoLocList lua require("todo-comments.search").setloclist(<f-args>)
command! -nargs=* TodoTelescope Telescope todo-comments todo <args>
command! -nargs=* TodoTrouble Trouble todo <args>

0 comments on commit c641728

Please sign in to comment.