diff --git a/lua/snacks/picker/config/sources.lua b/lua/snacks/picker/config/sources.lua index fe8e93b1..96718796 100644 --- a/lua/snacks/picker/config/sources.lua +++ b/lua/snacks/picker/config/sources.lua @@ -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? symbol kind filter ---@field tree? boolean show symbol tree diff --git a/lua/snacks/picker/format.lua b/lua/snacks/picker/format.lua index c51cd60d..b27b5814 100644 --- a/lua/snacks/picker/format.lua +++ b/lua/snacks/picker/format.lua @@ -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] = { " " } diff --git a/lua/snacks/picker/source/vim.lua b/lua/snacks/picker/source/vim.lua index a622316b..b8854876 100644 --- a/lua/snacks/picker/source/vim.lua +++ b/lua/snacks/picker/source/vim.lua @@ -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) diff --git a/lua/snacks/picker/types.lua b/lua/snacks/picker/types.lua index d2409580..625e5bf2 100644 --- a/lua/snacks/picker/types.lua +++ b/lua/snacks/picker/types.lua @@ -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