Collapse groups like explorer in picker? Or use the explorer on a picker buffer? #2867
Answered
by
drowning-cat
ssteinbach
asked this question in
Q&A
Replies: 1 comment 1 reply
:lua Snacks.picker.treesitter({ layout = { preset = "left" } })---@module 'snacks'
return {
"folke/snacks.nvim",
priority = 1000,
lazy = false,
---@type snacks.Config
opts = {
picker = {
sources = {
treesitter = {
fold_all = false,
finder = function(opts, ctx)
local next_items = require("snacks.picker.source.treesitter").symbols(opts, ctx) --[=[@as snacks.picker.finder.Item[]]=]
local prev_items = ctx.picker:items()
local ts_id = function(item)
return vim.inspect({ item.name, item.depth, item.pos, item.end_pos })
end
for _, item in ipairs(next_items) do
local id = ts_id(item)
local prev = vim.iter(prev_items):find(function(cit)
return id == ts_id(cit)
end)
item.children = item.children or {}
if item.parent then
item.parent.children = item.parent.children or {}
table.insert(item.parent.children, item)
end
if prev then
item.fold = prev.fold
else
if opts.fold_all and not vim.tbl_isempty(item.children) then
item.fold = true
else
item.fold = false
end
end
end
return next_items
end,
transform = function(item)
while item and item.parent do
item = item.parent
if item.fold == true then
return false
end
end
return true
end,
format = function(item, picker)
local fmt = Snacks.picker.format.lsp_symbol(item, picker)
if item.fold and not vim.tbl_isempty(item.children) then
table.insert(fmt, 3, { "" })
end
return fmt
end,
actions = {
toggle_fold = function(picker, item)
if not vim.tbl_isempty(item.children) then
item.fold = not item.fold
picker.list:set_target(item.idx)
picker:find()
end
end,
},
win = {
input = {
keys = {
["<C-z>"] = { "toggle_fold", mode = { "i", "n" } },
},
},
list = {
keys = {
["<C-z>"] = "toggle_fold",
},
},
},
},
},
},
},
} |
1 reply
Answer selected by
ssteinbach
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, I have a large file that i'm using the snacks.picker.treesitter to explore the structure of. is there a way to collapse groupings in snacks.picker like in explorer? Or alternatively could I use snacks.explorer to view a source from the picker?
Thanks all! Appreciate the great work on snacks.
All reactions