diff --git a/README.md b/README.md index 06c1022..e44c2bd 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,21 @@ Use Trouble's filtering: `Trouble todo filter = {tag = {TODO,FIX,FIXME}}` Search through all project todos with Telescope +This command accepts the following optional arguments: + +- `path` - Change how paths are displayed in the results. + +```vim +:TodoTelescope path=false +:TodoTelescope path=name +``` + +- `position` - Disable the line and column numbers. + +```vim +:TodoTelescope position=false +``` + ![image](https://user-images.githubusercontent.com/292349/118135371-ccb91200-b3b7-11eb-9002-66af3b683cf0.png) > [!Note] @@ -191,3 +206,4 @@ Search through all project todos with Telescope + diff --git a/lua/telescope/_extensions/todo-comments.lua b/lua/telescope/_extensions/todo-comments.lua index 63b7b1b..5ce53cb 100644 --- a/lua/telescope/_extensions/todo-comments.lua +++ b/lua/telescope/_extensions/todo-comments.lua @@ -21,6 +21,17 @@ local function keywords_filter(opts_keywords) end, all_keywords) end +local function format_display(entry, opts) + if opts.path == false then return "" end + local filename = opts.path == "name" and vim.fn.fnamemodify(entry.filename, ":t") or entry.filename + + if opts.position == false then + return string.format("%s ", filename) + else + return string.format("%s:%s:%s ", filename, entry.lnum, entry.col) + end +end + local function todo(opts) opts = opts or {} opts.vimgrep_arguments = { Config.options.search.command } @@ -33,7 +44,8 @@ local function todo(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 display = format_display(entry, opts) + local text = entry.text local start, finish, kw = Highlight.match(text)