@@ -5,8 +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 BaseNode = require " nvim-tree.node"
9- local DirectoryNode = require " nvim-tree.node.directory"
8+ local RootNode = require " nvim-tree.node.root"
109local Watcher = require " nvim-tree.watcher"
1110
1211local Iterator = require " nvim-tree.iterators.node-iterator"
@@ -23,19 +22,20 @@ local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
2322
2423local config
2524
26- --- @class (exact ) Explorer : DirectoryNode
25+ --- @class (exact ) Explorer : RootNode
2726--- @field opts table user options
2827--- @field renderer Renderer
2928--- @field filters Filters
3029--- @field live_filter LiveFilter
3130--- @field sorters Sorter
3231--- @field marks Marks
3332--- @field clipboard Clipboard
34- local Explorer = BaseNode . new (DirectoryNode ) -- TODO do not inherit, add a root node to separate Explorer and Node
33+ local Explorer = RootNode : new ()
3534
36- --- @param path string | nil
37- --- @return Explorer | nil
38- function Explorer :new (path )
35+ --- Static factory method
36+ --- @param path string ?
37+ --- @return Explorer ?
38+ function Explorer :create (path )
3939 local err
4040
4141 if path then
@@ -45,19 +45,19 @@ function Explorer:new(path)
4545 end
4646 if not path then
4747 notify .error (err )
48- return
48+ return nil
4949 end
5050
5151 --- @type Explorer
52- local placeholder = nil
52+ local explorer_placeholder
5353
54- local o = DirectoryNode .new (self , placeholder , nil , path , " .." , nil )
55- --- @cast o Explorer
54+ local o = RootNode .create (self , explorer_placeholder , path , " .." , nil ) --[[ @as Explorer]]
5655
5756 o .explorer = o
58- o .open = true
5957
58+ o .open = true
6059 o .opts = config
60+
6161 o .sorters = Sorters :new (config )
6262 o .renderer = Renderer :new (config , o )
6363 o .filters = Filters :new (config , o )
@@ -121,7 +121,7 @@ function Explorer:reload(node, git_status)
121121 })
122122
123123 while true do
124- local name , _ = vim .loop .fs_scandir_next (handle )
124+ local name , t = vim .loop .fs_scandir_next (handle )
125125 if not name then
126126 break
127127 end
@@ -134,22 +134,19 @@ function Explorer:reload(node, git_status)
134134 if filter_reason == FILTER_REASON .none then
135135 remain_childs [abs ] = true
136136
137- -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
138- local type = stat and stat .type or nil
139-
140137 -- Recreate node if type changes.
141138 if nodes_by_path [abs ] then
142139 local n = nodes_by_path [abs ]
143140
144- if n .type ~= type then
141+ if n .type ~= t then
145142 utils .array_remove (node .nodes , n )
146143 n :destroy ()
147144 nodes_by_path [abs ] = nil
148145 end
149146 end
150147
151148 if not nodes_by_path [abs ] then
152- local new_child = node_factory .create_node (self , node , abs , stat , name )
149+ local new_child = node_factory .create_node (self , node , abs , t , stat , name )
153150 if new_child then
154151 table.insert (node .nodes , new_child )
155152 nodes_by_path [abs ] = new_child
@@ -340,21 +337,21 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
340337 })
341338
342339 while true do
343- local name , _ = vim .loop .fs_scandir_next (handle )
340+ local name , t = vim .loop .fs_scandir_next (handle )
344341 if not name then
345342 break
346343 end
347344
348345 local abs = utils .path_join { cwd , name }
349346
350347 if Watcher .is_fs_event_capable (abs ) then
351- local profile = log .profile_start (" populate_children %s" , abs )
348+ local profile = log .profile_start (" explore populate_children %s" , abs )
352349
353350 --- @type uv.fs_stat.result | nil
354351 local stat = vim .loop .fs_stat (abs )
355352 local filter_reason = parent .filters :should_filter_as_reason (abs , stat , filter_status )
356353 if filter_reason == FILTER_REASON .none and not nodes_by_path [abs ] then
357- local child = node_factory .create_node (self , node , abs , stat , name )
354+ local child = node_factory .create_node (self , node , abs , t , stat , name )
358355 if child then
359356 table.insert (node .nodes , child )
360357 nodes_by_path [child .absolute_path ] = true
0 commit comments