Skip to content

Commit

Permalink
feat: Telescope plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 10, 2021
1 parent 2675b68 commit 95f04b1
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lua/telescope/_extensions/todo-comments.lua
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 } }

0 comments on commit 95f04b1

Please sign in to comment.