@@ -5,6 +5,7 @@ local utils = require("nvim-tree.utils")
55local view = require (" nvim-tree.view" )
66local node_factory = require (" nvim-tree.node.factory" )
77
8+ local DirectoryNode = require (" nvim-tree.node.directory" )
89local RootNode = require (" nvim-tree.node.root" )
910local Watcher = require (" nvim-tree.watcher" )
1011
@@ -72,12 +73,12 @@ function Explorer:create(path)
7273 return o
7374end
7475
75- --- @param node Node
76+ --- @param node DirectoryNode
7677function Explorer :expand (node )
7778 self :_load (node )
7879end
7980
80- --- @param node Node
81+ --- @param node DirectoryNode
8182--- @param git_status table | nil
8283function Explorer :reload (node , git_status )
8384 local cwd = node .link_to or node .absolute_path
@@ -169,17 +170,10 @@ function Explorer:reload(node, git_status)
169170 end , node .nodes )
170171 )
171172
172- local is_root = not node .parent
173- ---
174- --- @cast node DirectoryNode
175- ---
176- local child_folder_only = node :has_one_child_folder () and node .nodes [1 ]
177- ---
178- --- @cast child_folder_only DirectoryNode
179- ---
180- if config .renderer .group_empty and not is_root and child_folder_only then
181- node .group_next = child_folder_only
182- local ns = self :reload (child_folder_only , git_status )
173+ local single_child = node :single_child_directory ()
174+ if config .renderer .group_empty and node .parent and single_child then
175+ node .group_next = single_child
176+ local ns = self :reload (single_child , git_status )
183177 node .nodes = ns or {}
184178 log .profile_end (profile )
185179 return ns
@@ -225,7 +219,7 @@ function Explorer:refresh_parent_nodes_for_path(path)
225219end
226220
227221--- @private
228- --- @param node Node
222+ --- @param node DirectoryNode
229223function Explorer :_load (node )
230224 local cwd = node .link_to or node .absolute_path
231225 local git_status = git .load_project_status (cwd )
@@ -301,7 +295,7 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
301295end
302296
303297--- @private
304- --- @param node Node
298+ --- @param node DirectoryNode
305299--- @param status table
306300--- @param parent Explorer
307301--- @return Node[] | nil
@@ -317,18 +311,12 @@ function Explorer:explore(node, status, parent)
317311 self :populate_children (handle , cwd , node , status , parent )
318312
319313 local is_root = not node .parent
320- ---
321- --- @cast node DirectoryNode
322- ---
323- local child_folder_only = node :has_one_child_folder () and node .nodes [1 ]
324- ---
325- --- @cast child_folder_only DirectoryNode
326- ---
327- if config .renderer .group_empty and not is_root and child_folder_only then
328- local child_cwd = child_folder_only .link_to or child_folder_only .absolute_path
314+ local single_child = node :single_child_directory ()
315+ if config .renderer .group_empty and not is_root and single_child then
316+ local child_cwd = single_child .link_to or single_child .absolute_path
329317 local child_status = git .load_project_status (child_cwd )
330- node .group_next = child_folder_only
331- local ns = self :explore (child_folder_only , child_status , parent )
318+ node .group_next = single_child
319+ local ns = self :explore (single_child , child_status , parent )
332320 node .nodes = ns or {}
333321
334322 log .profile_end (profile )
347335function Explorer :refresh_nodes (projects )
348336 Iterator .builder ({ self })
349337 :applier (function (n )
350- if n .nodes then
351- local toplevel = git .get_toplevel (n .cwd or n .link_to or n .absolute_path )
352- self :reload (n , projects [toplevel ] or {})
338+ local dir = n :as (DirectoryNode )
339+ if dir then
340+ local toplevel = git .get_toplevel (dir .cwd or dir .link_to or dir .absolute_path )
341+ self :reload (dir , projects [toplevel ] or {})
353342 end
354343 end )
355344 :recursor (function (n )
0 commit comments