From 21bfcc3e397961b804241cc056a4c64f214c71f7 Mon Sep 17 00:00:00 2001 From: Ruben Laguna Date: Wed, 25 Sep 2024 03:47:39 +0200 Subject: [PATCH] feat(tags): add support for displaying tag kind (#3235) * 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 Co-authored-by: Github Actions --- lua/telescope/make_entry.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 3f42d176f1..3920e2623d 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -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 }, } @@ -1062,6 +1064,7 @@ function make_entry.gen_from_ctags(opts) end, }, entry.tag, + entry.kind, scode, } end @@ -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, "/", "\\") @@ -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