feat(picker): added Snacks.picker.tags() a picker for ctags. Closes #1728

This commit is contained in:
Folke Lemaitre 2025-10-22 14:44:02 +02:00
parent de1b7a8729
commit 42902871f5
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
4 changed files with 61 additions and 1 deletions

View file

@ -849,6 +849,14 @@ M.spelling = {
confirm = "item_action",
}
-- Search tags file
---@class snacks.picker.tags.Config: snacks.picker.Config
M.tags = {
workspace = true, -- search tags in the workspace
finder = "vim_tags",
format = "lsp_symbol",
}
---@class snacks.picker.treesitter.Config: snacks.picker.Config
---@field filter table<string, string[]|boolean>? symbol kind filter
---@field tree? boolean show symbol tree

View file

@ -313,7 +313,8 @@ function M.lsp_symbol(item, picker)
if item.tree and not opts.workspace then
vim.list_extend(ret, M.tree(item, picker))
end
local kind = item.kind or "Unknown" ---@type string
local kind = item.lsp_kind or item.kind or "Unknown" ---@type string
kind = picker.opts.icons.kinds[kind] and kind or "Unknown"
local kind_hl = "SnacksPickerIcon" .. kind
ret[#ret + 1] = { picker.opts.icons.kinds[kind], kind_hl }
ret[#ret + 1] = { " " }

View file

@ -319,6 +319,56 @@ function M.spelling()
return items
end
---@class snacks.picker.tags.Tag
---@field name string
---@field filename string
---@field cmd string
---@field kind? string
---@field static? string
---@param opts snacks.picker.tags.Config
---@type snacks.picker.finder
function M.tags(opts, ctx)
local buf = ctx.filter.current_buf
---@type snacks.picker.tags.Tag[]
local tags = vim.fn.taglist(ctx.filter.search == "" and ".*" or ctx.filter.search, vim.api.nvim_buf_get_name(buf))
local ret = {} ---@type snacks.picker.finder.Item[]
local lsp_kinds = {
c = "Class",
d = "Constant",
e = "Enum",
f = "Function",
g = "EnumMember",
l = "Variable",
m = "Method",
s = "Struct",
t = "TypeParameter",
v = "Variable",
F = "Field",
M = "Module",
n = "Namespace",
P = "Property",
S = "Struct",
T = "TypeParameter",
}
for _, tag in ipairs(tags) do
---@type snacks.picker.finder.Item
local item = {
text = tag.name,
name = tag.name,
file = tag.filename,
search = tag.cmd,
kind = tag.kind,
lsp_kind = lsp_kinds[tag.kind] or "Text",
}
ret[#ret + 1] = item
end
return ret
end
---@param opts snacks.picker.undo.Config
---@type snacks.picker.finder
function M.undo(opts, ctx)

View file

@ -57,6 +57,7 @@
---@field search_history fun(opts?: snacks.picker.history.Config|{}): snacks.Picker
---@field smart fun(opts?: snacks.picker.smart.Config|{}): snacks.Picker
---@field spelling fun(opts?: snacks.picker.Config|{}): snacks.Picker
---@field tags fun(opts?: snacks.picker.tags.Config|{}): snacks.Picker
---@field treesitter fun(opts?: snacks.picker.treesitter.Config|{}): snacks.Picker
---@field undo fun(opts?: snacks.picker.undo.Config|{}): snacks.Picker
---@field zoxide fun(opts?: snacks.picker.Config|{}): snacks.Picker