Skip to content

Commit dcaf852

Browse files
committed
move watcher to DirectoryNode
1 parent 8b313ab commit dcaf852

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

lua/nvim-tree/api.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ local function open_or_expand_or_dir_up(mode, toggle_group)
217217
if node.name == ".." then
218218
actions.root.change_dir.fn("..")
219219
elseif node:is(DirectoryNode) then
220-
---
221-
---@cast node DirectoryNode
222-
---
223220
node:expand_or_collapse(toggle_group)
224221
elseif not toggle_group then
225222
edit(mode, node)

lua/nvim-tree/node/directory.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local Node = require("nvim-tree.node")
88
---@field group_next DirectoryNode? -- If node is grouped, this points to the next child dir/link node
99
---@field nodes Node[]
1010
---@field open boolean
11+
---@field watcher Watcher?
1112
---@field hidden_stats table? -- Each field of this table is a key for source and value for count
1213
local DirectoryNode = Node:new()
1314

@@ -51,12 +52,18 @@ function DirectoryNode:create(explorer, parent, absolute_path, name, fs_stat)
5152
end
5253

5354
function DirectoryNode:destroy()
54-
Node.destroy(self)
55+
if self.watcher then
56+
self.watcher:destroy()
57+
self.watcher = nil
58+
end
59+
5560
if self.nodes then
5661
for _, node in pairs(self.nodes) do
5762
node:destroy()
5863
end
5964
end
65+
66+
Node.destroy(self)
6067
end
6168

6269
---Update the GitStatus of the directory

lua/nvim-tree/node/file.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function FileNode:create(explorer, parent, absolute_path, name, fs_stat)
2727
is_dot = false,
2828
name = name,
2929
parent = parent,
30-
watcher = nil,
3130
diag_status = nil,
3231

3332
extension = string.match(name, ".?[^.]+%.(.*)") or "",

lua/nvim-tree/node/init.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,19 @@ local Class = require("nvim-tree.class")
1818
---@field hidden boolean
1919
---@field name string
2020
---@field parent DirectoryNode?
21-
---@field watcher Watcher?
2221
---@field diag_status DiagStatus?
2322
---@field is_dot boolean cached is_dotfile
2423
local Node = Class:new()
2524

2625
function Node:destroy()
27-
if self.watcher then
28-
self.watcher:destroy()
29-
self.watcher = nil
30-
end
3126
end
3227

3328
--luacheck: push ignore 212
3429
---Update the GitStatus of the node
3530
---@param parent_ignored boolean
3631
---@param status table?
3732
function Node:update_git_status(parent_ignored, status) ---@diagnostic disable-line: unused-local
33+
---TODO find a way to declare abstract methods
3834
end
3935

4036
--luacheck: pop
@@ -149,7 +145,6 @@ function Node:clone()
149145
is_dot = self.is_dot,
150146
name = self.name,
151147
parent = nil,
152-
watcher = nil,
153148
diag_status = nil,
154149
}
155150

0 commit comments

Comments
 (0)