Skip to content

Commit

Permalink
feat!: replace todo-comments.nvim
Browse files Browse the repository at this point in the history
Highlightning is done via mini.hipatterns so the only reason to keep
todo-comments was `:TodoQuickFix`. As a replacement I wrote a very
light-weight and basic function. Of course, the plugin is more
sophisticated but for my use-case I hope that my custom
solution is enough :)
  • Loading branch information
Allaman committed Aug 21, 2023
1 parent 0ef8f56 commit 3d740af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lua/core/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ map("n", "<leader>ms", "<cmd>source ~/.config/nvim/snippets/*<cr>", { desc = "Re
map("n", "<leader>qj", "<cmd>cnext<cr>", { desc = "Next entry" })
map("n", "<leader>qk", "<cmd>cprevious<cr>", { desc = "Previous entry" })
map("n", "<leader>qq", "<cmd>lua require('core.utils.functions').toggle_qf()<cr>", { desc = "Toggle Quickfix" })
-- Search for 'FIXME', 'HACK', 'TODO', 'NOTE'
map("n", "<leader>qt", function()
utils.search_todos()
end, { desc = "List TODOs" })
12 changes: 0 additions & 12 deletions lua/core/plugins/todo-comments.lua

This file was deleted.

37 changes: 37 additions & 0 deletions lua/core/utils/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,41 @@ M.table_length = function(t)
return count
end

---Search for TODO|HACK|FIXME|NOTE with rg and
---populate quickfixlist with the results
M.search_todos = function()
local result
result = vim.fn.system("rg --json --case-sensitive -w 'TODO|HACK|FIXME|NOTE'")
if result == nil then
return
end
local lines = vim.split(result, "\n")
local qf_list = {}

for _, line in ipairs(lines) do
if line ~= "" then
local data = vim.fn.json_decode(line)
if data ~= nil then
if data.type == "match" then
local submatches = data.data.submatches[1]
table.insert(qf_list, {
filename = data.data.path.text,
lnum = data.data.line_number,
col = submatches.start,
text = data.data.lines.text,
})
end
end
end
end

if next(qf_list) ~= nil then
vim.fn.setqflist(qf_list)
vim.cmd("copen")
else
local utils = require("core.utils.functions")
utils.notify("No results found!", vim.log.levels.INFO, "Search TODOs")
end
end

return M

0 comments on commit 3d740af

Please sign in to comment.