mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
refactor(picker): indent/hierarchy => tree
This commit is contained in:
parent
3564f4fede
commit
7ad414e8a9
5 changed files with 15 additions and 15 deletions
|
@ -283,7 +283,7 @@ local defaults = {
|
|||
keymaps = {
|
||||
nowait = " "
|
||||
},
|
||||
indent = {
|
||||
tree = {
|
||||
vertical = "│ ",
|
||||
middle = "├╴",
|
||||
last = "└╴",
|
||||
|
|
|
@ -29,7 +29,7 @@ Snacks.util.set_hl({
|
|||
Unselected = "NonText",
|
||||
Idx = "Number",
|
||||
Bold = "Bold",
|
||||
Indent = "LineNr",
|
||||
Tree = "LineNr",
|
||||
Italic = "Italic",
|
||||
Code = "@markup.raw.markdown_inline",
|
||||
AuPattern = "String",
|
||||
|
|
|
@ -417,13 +417,13 @@ M.lsp_references = {
|
|||
|
||||
-- LSP document symbols
|
||||
---@class snacks.picker.lsp.symbols.Config: snacks.picker.Config
|
||||
---@field hierarchy? boolean show symbol hierarchy
|
||||
---@field tree? boolean show symbol tree
|
||||
---@field filter table<string, string[]|boolean>? symbol kind filter
|
||||
---@field workspace? boolean show workspace symbols
|
||||
M.lsp_symbols = {
|
||||
finder = "lsp_symbols",
|
||||
format = "lsp_symbol",
|
||||
hierarchy = true,
|
||||
tree = true,
|
||||
filter = {
|
||||
default = {
|
||||
"Class",
|
||||
|
@ -465,7 +465,7 @@ M.lsp_symbols = {
|
|||
---@type snacks.picker.lsp.symbols.Config
|
||||
M.lsp_workspace_symbols = vim.tbl_extend("force", {}, M.lsp_symbols, {
|
||||
workspace = true,
|
||||
hierarchy = false,
|
||||
tree = false,
|
||||
supports_live = true,
|
||||
live = true, -- live by default
|
||||
})
|
||||
|
|
|
@ -97,7 +97,7 @@ function M.file(item, picker)
|
|||
end
|
||||
|
||||
if item.parent then
|
||||
vim.list_extend(ret, M.indent(item, picker))
|
||||
vim.list_extend(ret, M.tree(item, picker))
|
||||
end
|
||||
|
||||
vim.list_extend(ret, M.filename(item, picker))
|
||||
|
@ -190,22 +190,22 @@ function M.git_stash(item, picker)
|
|||
return ret
|
||||
end
|
||||
|
||||
function M.indent(item, picker)
|
||||
function M.tree(item, picker)
|
||||
local ret = {} ---@type snacks.picker.Highlight[]
|
||||
local indents = picker.opts.icons.indent
|
||||
local icons = picker.opts.icons.tree
|
||||
local indent = {} ---@type string[]
|
||||
local node = item
|
||||
while node and node.parent do
|
||||
local is_last, icon = node.last, ""
|
||||
if node ~= item then
|
||||
icon = is_last and " " or indents.vertical
|
||||
icon = is_last and " " or icons.vertical
|
||||
else
|
||||
icon = is_last and indents.last or indents.middle
|
||||
icon = is_last and icons.last or icons.middle
|
||||
end
|
||||
table.insert(indent, 1, icon)
|
||||
node = node.parent
|
||||
end
|
||||
ret[#ret + 1] = { table.concat(indent), "SnacksPickerIndent" }
|
||||
ret[#ret + 1] = { table.concat(indent), "SnacksPickerTree" }
|
||||
return ret
|
||||
end
|
||||
|
||||
|
@ -218,7 +218,7 @@ function M.undo(item, picker)
|
|||
else
|
||||
ret[#ret + 1] = { a("", 2) }
|
||||
end
|
||||
vim.list_extend(ret, M.indent(item, picker))
|
||||
vim.list_extend(ret, M.tree(item, picker))
|
||||
|
||||
ret[#ret + 1] = { a(tostring(entry.seq), 4), "SnacksPickerIdx" }
|
||||
ret[#ret + 1] = { " " }
|
||||
|
@ -241,8 +241,8 @@ end
|
|||
function M.lsp_symbol(item, picker)
|
||||
local opts = picker.opts --[[@as snacks.picker.lsp.symbols.Config]]
|
||||
local ret = {} ---@type snacks.picker.Highlight[]
|
||||
if item.hierarchy and not opts.workspace then
|
||||
vim.list_extend(ret, M.indent(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_hl = "SnacksPickerIcon" .. kind
|
||||
|
|
|
@ -369,7 +369,7 @@ function M.symbols(opts, ctx)
|
|||
end,
|
||||
})
|
||||
for _, item in ipairs(items) do
|
||||
item.hierarchy = opts.hierarchy
|
||||
item.tree = opts.tree
|
||||
---@diagnostic disable-next-line: await-in-sync
|
||||
cb(item)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue