Fix tagrelative option not considered in builtin.tags

This commit is contained in:
Oscar Creator
2023-06-24 11:04:27 +02:00
parent ffe35cb433
commit fb03f02a9f
2 changed files with 31 additions and 2 deletions
+17 -1
View File
@@ -529,6 +529,22 @@ files.current_buffer_fuzzy_find = function(opts)
end
files.tags = function(opts)
local tags_command = (function()
if 1 == vim.fn.executable "rg" then
return { "rg", "-H", "-N", "--no-heading", "--color", "never", "^" }
elseif 1 == vim.fn.executable "grep" then
return { "grep", "-H", "--color=never", "^"}
end
end)()
if not tags_command then
utils.notify("builtin.find_files", {
msg = "You need to install either grep or rg",
level = "ERROR",
})
return
end
local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles()
for i, ctags_file in ipairs(tagfiles) do
tagfiles[i] = vim.fn.expand(ctags_file, true)
@@ -545,7 +561,7 @@ files.tags = function(opts)
pickers
.new(opts, {
prompt_title = "Tags",
finder = finders.new_oneshot_job(flatten { "cat", tagfiles }, opts),
finder = finders.new_oneshot_job(flatten { tags_command, tagfiles }, opts),
previewer = previewers.ctags.new(opts),
sorter = conf.generic_sorter(opts),
attach_mappings = function()
+14 -1
View File
@@ -1086,7 +1086,14 @@ function make_entry.gen_from_ctags(opts)
local current_file_cache = {}
return function(line)
if line == "" or line:sub(1, 1) == "!" then
if line == "" then
return nil
end
local tag_file
tag_file, line = string.match(line, '([^:]+):(.+)')
-- do not include tag file format
if line:sub(1, 1) == "!" then
return nil
end
@@ -1098,6 +1105,12 @@ function make_entry.gen_from_ctags(opts)
tag, file, lnum = string.match(line, "([^\t]+)\t([^\t]+)\t(%d+).*")
end
-- 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
end
if Path.path.sep == "\\" then
file = string.gsub(file, "/", "\\")
end