@@ -27,19 +27,30 @@ local function expand(node)
27
27
end
28
28
end
29
29
30
+ --- @param should_descend fun ( expansion_count : integer , node : Node ): boolean
31
+ --- @return fun ( expansion_count : integer , node : Node ): boolean
32
+ local function limit_folder_discovery (should_descend )
33
+ return function (expansion_count , node )
34
+ local should_halt = expansion_count >= M .MAX_FOLDER_DISCOVERY
35
+ if should_halt then
36
+ return false
37
+ end
38
+
39
+ return should_descend (expansion_count , node )
40
+ end
41
+ end
42
+
30
43
--- @param expansion_count integer
31
44
--- @param node Node
32
45
--- @return boolean
33
- local function descend_until_max_or_empty ( expansion_count , node )
46
+ local function descend_until_empty ( _ , node )
34
47
local dir = node :as (DirectoryNode )
35
48
if not dir then
36
49
return false
37
50
end
38
51
39
- local should_halt = expansion_count >= M .MAX_FOLDER_DISCOVERY
40
52
local should_exclude = M .EXCLUDE [dir .name ]
41
-
42
- return not should_halt and not should_exclude
53
+ return not should_exclude
43
54
end
44
55
45
56
--- @param expansion_count integer
@@ -122,7 +133,7 @@ local function expand_node(node, expand_opts)
122
133
if not node then
123
134
return
124
135
end
125
- local descend_until = ( expand_opts and expand_opts .expand_until ) or descend_until_max_or_empty
136
+ local descend_until = limit_folder_discovery (( expand_opts and expand_opts .expand_until ) or descend_until_empty )
126
137
if gen_iterator (descend_until )(node ) then
127
138
notify .warn (" expansion iteration was halted after " .. M .MAX_FOLDER_DISCOVERY .. " discovered folders" )
128
139
end
0 commit comments