-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local has_telescope, telescope = pcall(require, "telescope") | ||
|
||
if not has_telescope then | ||
error("This plugins requires nvim-telescope/telescope.nvim") | ||
end | ||
|
||
local pickers = require("telescope.builtin") | ||
local Config = require("todo-comments.config") | ||
local Highlight = require("todo-comments.highlight") | ||
local make_entry = require("telescope.make_entry") | ||
|
||
local function todo(opts) | ||
opts = opts or {} | ||
opts.search = Config.rg_regex | ||
opts.prompt_title = "Find Todo" | ||
opts.use_regex = true | ||
local entry_maker = make_entry.gen_from_vimgrep(opts) | ||
opts.entry_maker = function(line) | ||
local ret = entry_maker(line) | ||
ret.display = function(entry) | ||
local display = string.format("%s:%s:%s ", entry.filename, entry.lnum, | ||
entry.col) | ||
local text = entry.text | ||
local start, finish, kw = Highlight.match(text) | ||
|
||
local hl = {} | ||
|
||
if start then | ||
kw = Config.keywords[kw] or kw | ||
local icon = Config.options.keywords[kw].icon | ||
display = icon .. " " .. display | ||
table.insert(hl, { { 1, #icon + 1 }, "TodoFg" .. kw }) | ||
text = vim.trim(text:sub(start)) | ||
|
||
table.insert(hl, { | ||
{ #display, #display + finish - start + 2 }, | ||
"TodoBg" .. kw, | ||
}) | ||
table.insert(hl, { | ||
{ #display + finish - start + 1, #display + finish + 1 + #text }, | ||
"TodoFg" .. kw, | ||
}) | ||
display = display .. " " .. text | ||
end | ||
|
||
return display, hl | ||
end | ||
return ret | ||
end | ||
pickers.grep_string(opts) | ||
end | ||
|
||
return telescope.register_extension { exports = { todo = todo } } |