Skip to content

Commit fee6176

Browse files
committed
explorer is a directory node
1 parent b832342 commit fee6176

File tree

5 files changed

+17
-31
lines changed

5 files changed

+17
-31
lines changed

lua/nvim-tree.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ function M.setup(conf)
849849
require("nvim-tree.keymap").setup(opts)
850850
require("nvim-tree.appearance").setup()
851851
require("nvim-tree.diagnostics").setup(opts)
852-
require("nvim-tree.explorer").setup(opts)
852+
require("nvim-tree.explorer"):setup(opts)
853853
require("nvim-tree.git").setup(opts)
854854
require("nvim-tree.git.utils").setup(opts)
855855
require("nvim-tree.view").setup(opts)

lua/nvim-tree/explorer/init.lua

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ local log = require "nvim-tree.log"
33
local notify = require "nvim-tree.notify"
44
local utils = require "nvim-tree.utils"
55
local view = require "nvim-tree.view"
6-
local watch = require "nvim-tree.explorer.watch"
76
local explorer_node = require "nvim-tree.explorer.node"
87

98
local BaseNode = require "nvim-tree.node"
@@ -26,19 +25,15 @@ local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON
2625

2726
local config
2827

29-
---@class Explorer: BaseNode
28+
---@class (exact) Explorer: DirectoryNode
3029
---@field opts table user options
31-
---@field absolute_path string
32-
---@field nodes Node[]
33-
---@field open boolean
34-
---@field watcher Watcher|nil
3530
---@field renderer Renderer
3631
---@field filters Filters
3732
---@field live_filter LiveFilter
3833
---@field sorters Sorter
3934
---@field marks Marks
4035
---@field clipboard Clipboard
41-
local Explorer = BaseNode:new()
36+
local Explorer = BaseNode.new(DirectoryNode) -- TODO do not inherit, add a root node to separate Explorer and Node
4237

4338
---@param path string|nil
4439
---@return Explorer|nil
@@ -56,27 +51,16 @@ function Explorer:new(path)
5651
end
5752

5853
---@type Explorer
59-
local placeholder
60-
61-
local o = BaseNode.new(self, {
62-
type = "directory",
63-
explorer = placeholder,
64-
absolute_path = path,
65-
executable = false,
66-
hidden = false,
67-
is_dot = false,
68-
69-
has_children = false,
70-
group_next = nil,
71-
nodes = {},
72-
open = true,
73-
})
54+
local placeholder = nil
55+
56+
local o = DirectoryNode.new(self, placeholder, nil, path, nil, nil)
7457
---@cast o Explorer
7558

7659
o.explorer = self
60+
o.open = true
61+
7762
o.opts = config
7863
o.sorters = Sorters:new(config)
79-
o.watcher = watch.create_watcher(o)
8064
o.renderer = Renderer:new(config, o)
8165
o.filters = Filters:new(config, o)
8266
o.live_filter = LiveFilter:new(config, o)
@@ -490,7 +474,7 @@ function Explorer:reload_git()
490474
event_running = false
491475
end
492476

493-
function Explorer.setup(opts)
477+
function Explorer:setup(opts)
494478
config = opts
495479
require("nvim-tree.explorer.node").setup(opts)
496480
require("nvim-tree.explorer.watch").setup(opts)

lua/nvim-tree/node/directory.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ local watch = require "nvim-tree.explorer.watch"
33
local BaseNode = require "nvim-tree.node"
44

55
---@class (exact) DirectoryNode: BaseNode
6-
---@field has_children boolean
7-
---@field group_next Node|nil
6+
---@field has_children boolean -- TODO remove this and just test nodes
7+
---@field group_next Node|nil -- If node is grouped, this points to the next child dir/link node
88
---@field nodes Node[]
99
---@field open boolean
1010
---@field hidden_stats table -- Each field of this table is a key for source and value for count
@@ -13,7 +13,7 @@ local DirectoryNode = BaseNode:new()
1313
---@param explorer Explorer
1414
-----@param parent DirectoryNode -- TODO #2871 #2886
1515
---@param absolute_path string
16-
---@param name string
16+
---@param name string|nil
1717
---@param fs_stat uv.fs_stat.result|nil
1818
---@return DirectoryNode
1919
function DirectoryNode:new(explorer, parent, absolute_path, name, fs_stat)
@@ -32,7 +32,7 @@ function DirectoryNode:new(explorer, parent, absolute_path, name, fs_stat)
3232
parent = parent,
3333

3434
has_children = has_children,
35-
group_next = nil, -- If node is grouped, this points to the next child dir/link node
35+
group_next = nil,
3636
nodes = {},
3737
open = false,
3838
})

lua/nvim-tree/node/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
---@field diag_status DiagStatus|nil
1515
local BaseNode = {}
1616

17-
---@alias Node DirectoryNode|FileNode|LinkNode|Explorer
17+
---@alias Node DirectoryNode|FileNode|LinkNode
1818

1919
---@param o BaseNode|nil
2020
---@return BaseNode

lua/nvim-tree/node/link.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ local watch = require "nvim-tree.explorer.watch"
33
local BaseNode = require "nvim-tree.node"
44

55
---@class (exact) LinkNode: BaseNode
6+
---@field has_children boolean -- TODO remove this and just test nodes
7+
---@field group_next Node|nil -- If node is grouped, this points to the next child dir/link node
68
---@field link_to string absolute path
79
local LinkNode = BaseNode:new()
810

@@ -44,7 +46,7 @@ function LinkNode:new(explorer, parent, absolute_path, name, fs_stat)
4446
link_to = link_to,
4547

4648
has_children = has_children,
47-
group_next = nil, -- If node is grouped, this points to the next child dir/link node
49+
group_next = nil,
4850
nodes = nodes,
4951
open = open,
5052
})

0 commit comments

Comments
 (0)