1- local git = require " nvim-tree.git"
2- local log = require " nvim-tree.log"
3- local notify = require " nvim-tree.notify"
4- local utils = require " nvim-tree.utils"
5- local view = require " nvim-tree.view"
6- local node_factory = require " nvim-tree.node.factory"
1+ local git = require ( " nvim-tree.git" )
2+ local log = require ( " nvim-tree.log" )
3+ local notify = require ( " nvim-tree.notify" )
4+ local utils = require ( " nvim-tree.utils" )
5+ local view = require ( " nvim-tree.view" )
6+ local node_factory = require ( " nvim-tree.node.factory" )
77
8- local BaseNode = require " nvim-tree.node"
9- local DirectoryNode = require " nvim-tree.node.directory"
10- local Watcher = require " nvim-tree.watcher"
8+ local RootNode = require (" nvim-tree.node.root" )
9+ local Watcher = require (" nvim-tree.watcher" )
1110
1211local Iterator = require (" nvim-tree.iterators.node-iterator" )
1312local NodeIterator = 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 )
@@ -149,7 +149,7 @@ function Explorer:reload(node, git_status)
149149 end
150150
151151 if not nodes_by_path [abs ] then
152- local new_child = node_factory .create_node (self , node , abs , stat , name )
152+ local new_child = node_factory .create_node (self , node , abs , t , stat , name )
153153 if new_child then
154154 table.insert (node .nodes , new_child )
155155 nodes_by_path [abs ] = new_child
@@ -348,29 +348,15 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
348348 local abs = utils .path_join ({ cwd , name })
349349
350350 if Watcher .is_fs_event_capable (abs ) then
351- local profile = log .profile_start (" populate_children %s" , abs )
351+ local profile = log .profile_start (" explore populate_children %s" , abs )
352352
353353 --- @type uv.fs_stat.result | nil
354354 local stat = vim .loop .fs_lstat (abs )
355355 local filter_reason = parent .filters :should_filter_as_reason (abs , stat , filter_status )
356356 if filter_reason == FILTER_REASON .none and not nodes_by_path [abs ] then
357- <<<<<<< HEAD
358357 -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
359358 local t = stat and stat .type or nil
360- local child = nil
361- if t == " directory" and vim .loop .fs_access (abs , " R" ) then
362- child = DirectoryNode :new (self , node , abs , name , stat )
363- elseif t == " file" then
364- child = FileNode :new (self , node , abs , name , stat )
365- elseif t == " link" then
366- local link = LinkNode :new (self , node , abs , name , stat )
367- if link .link_to ~= nil then
368- child = link
369- end
370- end
371- =======
372- local child = node_factory .create_node (self , node , abs , stat , name )
373- >>>>>>> c02c98b (extract node factory , remove unused code )
359+ local child = node_factory .create_node (self , node , abs , t , stat , name )
374360 if child then
375361 table.insert (node .nodes , child )
376362 nodes_by_path [child .absolute_path ] = true
0 commit comments