Skip to content

Commit e8c4ce4

Browse files
committed
Pass function to populate_node to userland
1 parent 7cf4cf8 commit e8c4ce4

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local renderer = require "nvim-tree.renderer"
33
local Iterator = require "nvim-tree.iterators.node-iterator"
44
local notify = require "nvim-tree.notify"
55
local lib = require "nvim-tree.lib"
6+
local git = require "nvim-tree.git"
67

78
local M = {}
89

@@ -18,18 +19,28 @@ local function to_lookup_table(list)
1819
end
1920

2021
---@param node Node
21-
local function expand(node)
22-
node = lib.get_last_group_node(node)
23-
node.open = true
22+
local function populate_node(node)
23+
-- noop if it is a file
24+
if node.nodes == nil then
25+
return
26+
end
27+
local cwd = node.link_to or node.absolute_path
28+
local handle = vim.loop.fs_scandir(cwd)
29+
if not handle then
30+
return
31+
end
32+
local status = git.load_project_status(cwd)
33+
2434
if #node.nodes == 0 then
25-
core.get_explorer():expand(node)
35+
core.get_explorer():expand(node, status)
2636
end
2737
end
2838

2939
---@param expansion_count integer
3040
---@param node Node
41+
---@param populate_node function
3142
---@return boolean, function
32-
local function expand_until_max_or_empty(expansion_count, node)
43+
local function expand_until_max_or_empty(expansion_count, node, populate_node)
3344
local should_halt = expansion_count >= M.MAX_FOLDER_DISCOVERY
3445
local should_exclude = M.EXCLUDE[node.name]
3546
local result = not should_halt and node.nodes and not node.open and not should_exclude
@@ -40,16 +51,17 @@ local function gen_iterator(should_expand_fn)
4051
local expansion_count = 0
4152

4253
return function(parent)
43-
expand(parent)
54+
parent.open = true
4455

45-
Iterator.builder({parent})
56+
Iterator.builder({ parent })
4657
:hidden()
4758
:applier(function(node)
48-
local should_expand, should_expand_next_fn = should_expand_fn(expansion_count, node)
59+
local should_expand, should_expand_next_fn = should_expand_fn(expansion_count, node, populate_node)
4960
should_expand_fn = should_expand_next_fn
5061
if should_expand then
5162
expansion_count = expansion_count + 1
52-
expand(node)
63+
node = lib.get_last_group_node(node)
64+
node.open = true
5365
end
5466
end)
5567
:recursor(function(node)

0 commit comments

Comments
 (0)