From ba0073caeb5608106313b24b3fa2f22b2ec1a30b Mon Sep 17 00:00:00 2001 From: Oscar Creator Date: Sun, 25 Jun 2023 15:10:33 +0200 Subject: [PATCH] ctags filtering with grep or rg and normalize path --- lua/telescope/builtin/__files.lua | 5 +++-- lua/telescope/make_entry.lua | 13 +++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lua/telescope/builtin/__files.lua b/lua/telescope/builtin/__files.lua index 15c40f2..733a4b5 100644 --- a/lua/telescope/builtin/__files.lua +++ b/lua/telescope/builtin/__files.lua @@ -529,11 +529,12 @@ files.current_buffer_fuzzy_find = function(opts) end files.tags = function(opts) + -- find lines not matching tags file format (begins with !) or empty lines. local tags_command = (function() if 1 == vim.fn.executable "rg" then - return { "rg", "-H", "-N", "--no-heading", "--color", "never", "^" } + return { "rg", "-H", "-N", "--no-heading", "--color", "never", "-v", "^!|^$" } elseif 1 == vim.fn.executable "grep" then - return { "grep", "-H", "--color=never", "^"} + return { "grep", "-H", "--color=never", "-v", "^!\\|^$"} end end)() diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 444e91c..fdb04dc 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -1086,17 +1086,10 @@ function make_entry.gen_from_ctags(opts) local current_file_cache = {} return function(line) - if line == "" then - return nil - end local tag_file + -- split line by ':' tag_file, line = string.match(line, '([^:]+):(.+)') - -- do not include tag file format - if line:sub(1, 1) == "!" then - return nil - end - local tag, file, scode, lnum -- ctags gives us: 'tags\tfile\tsource' tag, file, scode = string.match(line, '([^\t]+)\t([^\t]+)\t/^?\t?(.*)/;"\t+.*') @@ -1107,8 +1100,8 @@ function make_entry.gen_from_ctags(opts) -- append tag file path if vim.opt.tagrelative:get() then - local tag_path = Path:new(tag_file):parent():make_relative(cwd) - file = tag_path .. "/" .. file + local tag_path = Path:new(tag_file):parent() + file = Path:new(tag_path .. "/" .. file):normalize(cwd) end if Path.path.sep == "\\" then