@@ -17,11 +17,9 @@ local function to_lookup_table(list)
1717 return table
1818end
1919
20- --- @param node Node
20+ --- @param node DirectoryNode
2121local function expand (node )
22- if node :is (DirectoryNode ) then
23- node = node :last_group_node ()
24- end
22+ node = node :last_group_node ()
2523 node .open = true
2624 if # node .nodes == 0 then
2725 core .get_explorer ():expand (node )
4038local function gen_iterator ()
4139 local expansion_count = 0
4240
41+ --- @param parent DirectoryNode
4342 return function (parent )
4443 if parent .parent and parent .nodes and not parent .open then
4544 expansion_count = expansion_count + 1
@@ -48,12 +47,14 @@ local function gen_iterator()
4847
4948 Iterator .builder (parent .nodes )
5049 :hidden ()
50+ --- @param node DirectoryNode
5151 :applier (function (node )
5252 if should_expand (expansion_count , node ) then
5353 expansion_count = expansion_count + 1
5454 expand (node )
5555 end
5656 end )
57+ --- @param node DirectoryNode
5758 :recursor (function (node )
5859 return expansion_count < M .MAX_FOLDER_DISCOVERY and (node .group_next and { node .group_next } or (node .open and node .nodes ))
5960 end )
@@ -65,11 +66,16 @@ local function gen_iterator()
6566 end
6667end
6768
69+ --- Expand the directory node or the root
6870--- @param node Node
6971function M .fn (node )
7072 local explorer = core .get_explorer ()
71- node = node .nodes and node or explorer
72- if gen_iterator ()(node ) then
73+ local parent = node :as (DirectoryNode ) or explorer
74+ if not parent then
75+ return
76+ end
77+
78+ if gen_iterator ()(parent ) then
7379 notify .warn (" expansion iteration was halted after " .. M .MAX_FOLDER_DISCOVERY .. " discovered folders" )
7480 end
7581 if explorer then
0 commit comments