feat: More auto-unfold options
Option to auto unfold when there is only N root nodes in outline. Defaults to 1, meaning if there is only one 'root' parent, it should always be unfolded. This is useful if the entire file is a single function or a single 'return'. The old auto_unfold_hover option **still works as expected**.
This commit is contained in:
@@ -60,7 +60,11 @@ M.defaults = {
|
||||
},
|
||||
symbol_folding = {
|
||||
autofold_depth = nil,
|
||||
auto_unfold_hover = true,
|
||||
auto_unfold_nodes = {
|
||||
hovered = true,
|
||||
---@type boolean|integer
|
||||
only = true,
|
||||
},
|
||||
markers = { '', '' },
|
||||
},
|
||||
keymaps = {
|
||||
@@ -306,6 +310,16 @@ function M.resolve_config()
|
||||
end
|
||||
----- SYMBOLS FILTER -----
|
||||
M.resolve_filter_config()
|
||||
----- AUTO UNFOLD -----
|
||||
local au = M.o.symbol_folding.auto_unfold_nodes
|
||||
if M.o.symbol_folding.auto_unfold_hover == nil then
|
||||
if au.hovered ~= nil then
|
||||
M.o.symbol_folding.auto_unfold_hover = au.hovered
|
||||
end
|
||||
end
|
||||
if type(au.only) ~= 'number' then
|
||||
au.only = (au.only and 1) or 0
|
||||
end
|
||||
end
|
||||
|
||||
---Ensure l is either table, false, or nil. If not, print warning using given
|
||||
|
||||
@@ -18,9 +18,14 @@ end
|
||||
|
||||
---@param node outline.SymbolNode|outline.FlatSymbolNode
|
||||
function M.is_folded(node)
|
||||
local hover = cfg.o.symbol_folding.auto_unfold_hover
|
||||
local only = cfg.o.symbol_folding.auto_unfold_nodes.only
|
||||
|
||||
if node.folded ~= nil then
|
||||
return node.folded
|
||||
elseif node.hovered and cfg.o.symbol_folding.auto_unfold_hover then
|
||||
elseif node.parent.is_root and node.parent.child_count <= only then
|
||||
return false
|
||||
elseif node.hovered and hover then
|
||||
return false
|
||||
else
|
||||
return get_default_folded(node.depth)
|
||||
|
||||
@@ -79,7 +79,7 @@ end
|
||||
function M.parse(response, bufnr)
|
||||
local sorted = lsp_utils.sort_symbols(response)
|
||||
|
||||
return parse_result(sorted, nil, nil, nil, bufnr)
|
||||
return parse_result(sorted, nil, nil, { is_root = true, child_count = #sorted }, bufnr)
|
||||
end
|
||||
|
||||
---Iterator that traverses the tree parent first before children, returning each node.
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
---@field hierarchy boolean
|
||||
---@field children? outline.SymbolNode[]
|
||||
---@field traversal_child integer Should NOT be modified during iteration using parser.preorder_iter
|
||||
---@field is_root boolean?
|
||||
|
||||
---@class outline.FlatSymbolNode
|
||||
---@field name string
|
||||
@@ -55,6 +56,7 @@
|
||||
---@field hierarchy boolean
|
||||
---@field children? outline.FlatSymbolNode[]
|
||||
---@field traversal_child integer
|
||||
---@field is_root boolean?
|
||||
---@field line_in_outline integer
|
||||
---@field prefix_length integer
|
||||
---@field hovered boolean
|
||||
|
||||
Reference in New Issue
Block a user