Skip to content

Commit 06aad16

Browse files
committed
Add documentation
1 parent 7bda685 commit 06aad16

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

doc/nvim-tree-lua.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,10 +1808,29 @@ tree.collapse_all({keep_buffers}) *nvim-tree-api.tree.collapse_all()*
18081808
Parameters: ~
18091809
• {keep_buffers} (boolean) do not collapse nodes with open buffers.
18101810

1811-
tree.expand_all() *nvim-tree-api.tree.expand_all()*
1811+
tree.expand_all({opts}) *nvim-tree-api.tree.expand_all()*
18121812
Recursively expand all nodes in the tree.
18131813
Folder: only the nodes underneath that folder.
18141814

1815+
Parameters: ~
1816+
{opts} (table) optional parameters
1817+
1818+
Options: ~
1819+
• {expand_until} (function) A function returning boolean that
1820+
specifies terminating condition for node/tree expansion. If not
1821+
provided the function that expands recursively entire node/tree will be
1822+
used.
1823+
Example: >
1824+
1825+
-- expand only 5 levels deep
1826+
local function my_expand(expansion_count, node)
1827+
local should_halt = expansion_count >= 5
1828+
return not should_halt
1829+
end
1830+
1831+
-- on_attach
1832+
vim.keymap.set('n', 'Z', api.tree.expand_all(node, { expand_until = my_expand }))
1833+
<
18151834
*nvim-tree-api.tree.toggle_enable_filters()*
18161835
tree.toggle_enable_filters()
18171836
Toggle |nvim-tree.filters.enable| all filters.

lua/nvim-tree/actions/tree/modifiers/expand-all.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ end
3939
local function expand_until_max_or_empty(expansion_count, node)
4040
local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY
4141
local should_exclude = M.EXCLUDE[node.name]
42-
local result = not should_halt and node.nodes and not node.open and not should_exclude
43-
return result
42+
return not should_halt and node.nodes and not node.open and not should_exclude
4443
end
4544

4645
local function gen_iterator(should_expand_fn)
@@ -74,8 +73,9 @@ local function gen_iterator(should_expand_fn)
7473
end
7574

7675
---@param base_node table
77-
function M.fn(base_node, expand_until)
78-
expand_until = expand_until or expand_until_max_or_empty
76+
---@param expand_opts ApiTreeExpandAllOpts|nil
77+
function M.fn(base_node, expand_opts)
78+
local expand_until = (expand_opts and expand_opts.expand_until) or expand_until_max_or_empty
7979
local node = base_node.nodes and base_node or core.get_explorer()
8080
if gen_iterator(expand_until)(node) then
8181
notify.warn("expansion iteration was halted after " .. M.MAX_FOLDER_DISCOVERY .. " discovered folders")

lua/nvim-tree/api.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ Api.tree.get_nodes = wrap(lib.get_nodes)
144144
Api.tree.find_file = wrap(actions.tree.find_file.fn)
145145
Api.tree.search_node = wrap(actions.finders.search_node.fn)
146146
Api.tree.collapse_all = wrap(actions.tree.modifiers.collapse_all.fn)
147+
148+
---@class ApiTreeExpandAllOpts
149+
---@field expand_until function|nil
150+
147151
Api.tree.expand_all = wrap_node(actions.tree.modifiers.expand_all.fn)
152+
148153
Api.tree.toggle_enable_filters = wrap(actions.tree.modifiers.toggles.enable)
149154
Api.tree.toggle_gitignore_filter = wrap(actions.tree.modifiers.toggles.git_ignored)
150155
Api.tree.toggle_git_clean_filter = wrap(actions.tree.modifiers.toggles.git_clean)

0 commit comments

Comments
 (0)