@@ -27,19 +27,30 @@ local function expand(node)
2727 end
2828end
2929
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+
3043--- @param expansion_count integer
3144--- @param node Node
3245--- @return boolean
33- local function descend_until_max_or_empty ( expansion_count , node )
46+ local function descend_until_empty ( _ , node )
3447 local dir = node :as (DirectoryNode )
3548 if not dir then
3649 return false
3750 end
3851
39- local should_halt = expansion_count >= M .MAX_FOLDER_DISCOVERY
4052 local should_exclude = M .EXCLUDE [dir .name ]
41-
42- return not should_halt and not should_exclude
53+ return not should_exclude
4354end
4455
4556--- @param expansion_count integer
@@ -122,7 +133,7 @@ local function expand_node(node, expand_opts)
122133 if not node then
123134 return
124135 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 )
126137 if gen_iterator (descend_until )(node ) then
127138 notify .warn (" expansion iteration was halted after " .. M .MAX_FOLDER_DISCOVERY .. " discovered folders" )
128139 end
0 commit comments