@@ -5,8 +5,7 @@ local utils = require "nvim-tree.utils"
5
5
local view = require " nvim-tree.view"
6
6
local node_factory = require " nvim-tree.node.factory"
7
7
8
- local BaseNode = require " nvim-tree.node"
9
- local DirectoryNode = require " nvim-tree.node.directory"
8
+ local RootNode = require " nvim-tree.node.root"
10
9
local Watcher = require " nvim-tree.watcher"
11
10
12
11
local Iterator = require " nvim-tree.iterators.node-iterator"
@@ -23,19 +22,20 @@ local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
23
22
24
23
local config
25
24
26
- --- @class (exact ) Explorer : DirectoryNode
25
+ --- @class (exact ) Explorer : RootNode
27
26
--- @field opts table user options
28
27
--- @field renderer Renderer
29
28
--- @field filters Filters
30
29
--- @field live_filter LiveFilter
31
30
--- @field sorters Sorter
32
31
--- @field marks Marks
33
32
--- @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 ()
35
34
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 )
39
39
local err
40
40
41
41
if path then
@@ -45,19 +45,19 @@ function Explorer:new(path)
45
45
end
46
46
if not path then
47
47
notify .error (err )
48
- return
48
+ return nil
49
49
end
50
50
51
51
--- @type Explorer
52
- local placeholder = nil
52
+ local explorer_placeholder
53
53
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]]
56
55
57
56
o .explorer = o
58
- o .open = true
59
57
58
+ o .open = true
60
59
o .opts = config
60
+
61
61
o .sorters = Sorters :new (config )
62
62
o .renderer = Renderer :new (config , o )
63
63
o .filters = Filters :new (config , o )
@@ -121,7 +121,7 @@ function Explorer:reload(node, git_status)
121
121
})
122
122
123
123
while true do
124
- local name , _ = vim .loop .fs_scandir_next (handle )
124
+ local name , t = vim .loop .fs_scandir_next (handle )
125
125
if not name then
126
126
break
127
127
end
@@ -134,22 +134,19 @@ function Explorer:reload(node, git_status)
134
134
if filter_reason == FILTER_REASON .none then
135
135
remain_childs [abs ] = true
136
136
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
-
140
137
-- Recreate node if type changes.
141
138
if nodes_by_path [abs ] then
142
139
local n = nodes_by_path [abs ]
143
140
144
- if n .type ~= type then
141
+ if n .type ~= t then
145
142
utils .array_remove (node .nodes , n )
146
143
n :destroy ()
147
144
nodes_by_path [abs ] = nil
148
145
end
149
146
end
150
147
151
148
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 )
153
150
if new_child then
154
151
table.insert (node .nodes , new_child )
155
152
nodes_by_path [abs ] = new_child
@@ -340,21 +337,21 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
340
337
})
341
338
342
339
while true do
343
- local name , _ = vim .loop .fs_scandir_next (handle )
340
+ local name , t = vim .loop .fs_scandir_next (handle )
344
341
if not name then
345
342
break
346
343
end
347
344
348
345
local abs = utils .path_join { cwd , name }
349
346
350
347
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 )
352
349
353
350
--- @type uv.fs_stat.result | nil
354
351
local stat = vim .loop .fs_stat (abs )
355
352
local filter_reason = parent .filters :should_filter_as_reason (abs , stat , filter_status )
356
353
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 )
358
355
if child then
359
356
table.insert (node .nodes , child )
360
357
nodes_by_path [child .absolute_path ] = true
0 commit comments