Skip to content

Commit

Permalink
feat(tags): add support for displaying tag kind (#3235)
Browse files Browse the repository at this point in the history
* Add kind to builtin.tags picker

* Add show_kind option

* Make show_kind true by default

* [docgen] Update doc/telescope.txt
skip-checks: true

* lint

---------

Co-authored-by: Ruben Laguna <ruben.laguna@tele2.com>
Co-authored-by: Github Actions <actions@github>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent b324469 commit 21bfcc3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,12 @@ end
function make_entry.gen_from_ctags(opts)
opts = opts or {}

local show_kind = vim.F.if_nil(opts.show_kind, true)
local cwd = utils.path_expand(opts.cwd or vim.loop.cwd())
local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):normalize(cwd)

local display_items = {
{ width = 16 },
{ remaining = true },
}

Expand Down Expand Up @@ -1062,6 +1064,7 @@ function make_entry.gen_from_ctags(opts)
end,
},
entry.tag,
entry.kind,
scode,
}
end
Expand Down Expand Up @@ -1089,13 +1092,14 @@ function make_entry.gen_from_ctags(opts)
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+.*')
local tag, file, scode, lnum, extension_fields
-- ctags gives us: 'tags\tfile\tsource;"extension_fields'
tag, file, scode, extension_fields = string.match(line, '([^\t]+)\t([^\t]+)\t/^?\t?(.*)/;"\t+(.*)')
if not tag then
-- hasktags gives us: 'tags\tfile\tlnum'
tag, file, lnum = string.match(line, "([^\t]+)\t([^\t]+)\t(%d+).*")
end
local kind = string.match(extension_fields or "", "kind:(%S+)")

if Path.path.sep == "\\" then
file = string.gsub(file, "/", "\\")
Expand Down Expand Up @@ -1124,6 +1128,9 @@ function make_entry.gen_from_ctags(opts)
tag_entry.filename = file
tag_entry.col = 1
tag_entry.lnum = lnum and tonumber(lnum) or 1
if show_kind then
tag_entry.kind = kind
end

return setmetatable(tag_entry, mt)
end
Expand Down

0 comments on commit 21bfcc3

Please sign in to comment.