From 3d740af343c169bde63dd317cebe3749297b3bc5 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 21 Aug 2023 21:18:57 +0200 Subject: [PATCH] feat!: replace todo-comments.nvim 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 :) --- lua/core/mappings.lua | 4 ++++ lua/core/plugins/todo-comments.lua | 12 ---------- lua/core/utils/functions.lua | 37 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 12 deletions(-) delete mode 100644 lua/core/plugins/todo-comments.lua diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 35aaa4da..91edbbc9 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -85,3 +85,7 @@ map("n", "ms", "source ~/.config/nvim/snippets/*", { desc = "Re map("n", "qj", "cnext", { desc = "Next entry" }) map("n", "qk", "cprevious", { desc = "Previous entry" }) map("n", "qq", "lua require('core.utils.functions').toggle_qf()", { desc = "Toggle Quickfix" }) +-- Search for 'FIXME', 'HACK', 'TODO', 'NOTE' +map("n", "qt", function() + utils.search_todos() +end, { desc = "List TODOs" }) diff --git a/lua/core/plugins/todo-comments.lua b/lua/core/plugins/todo-comments.lua deleted file mode 100644 index 4533c0af..00000000 --- a/lua/core/plugins/todo-comments.lua +++ /dev/null @@ -1,12 +0,0 @@ --- only for TodoQuickFix, highlighting is done by mini.hipatterns -local M = { - "folke/todo-comments.nvim", - keys = { - { "qt", "TodoQuickFix", desc = "Show TODOs" }, - }, - dependencies = { - "nvim-lua/plenary.nvim", - }, -} - -return M diff --git a/lua/core/utils/functions.lua b/lua/core/utils/functions.lua index f219a851..d4401853 100644 --- a/lua/core/utils/functions.lua +++ b/lua/core/utils/functions.lua @@ -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