diff --git a/lua/nvim-tree/explorer/node.lua b/lua/nvim-tree/explorer/node.lua index 0a3b9f3f..7eb17637 100644 --- a/lua/nvim-tree/explorer/node.lua +++ b/lua/nvim-tree/explorer/node.lua @@ -121,6 +121,7 @@ function M.node_destroy(node) if node.watcher then node.watcher:destroy() + node.watcher = nil end end diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index a24b0871..e80d8829 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -51,6 +51,9 @@ function M.create_watcher(node) local function callback(watcher) log.line("watcher", "node event scheduled refresh %s", watcher.context) utils.debounce(watcher.context, M.debounce_delay, function() + if watcher.destroyed then + return + end if node.link_to then log.line("watcher", "node event executing refresh '%s' -> '%s'", node.link_to, node.absolute_path) else diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 0070d877..7bf7f542 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -150,6 +150,9 @@ function M.load_project_status(cwd) local callback = function(w) log.line("watcher", "git event scheduled '%s'", w.project_root) utils.debounce("git:watcher:" .. w.project_root, M.config.filesystem_watchers.debounce_delay, function() + if w.destroyed then + return + end reload_tree_at(w.project_root) end) end diff --git a/lua/nvim-tree/watcher.lua b/lua/nvim-tree/watcher.lua index da8e6477..b5473ca6 100644 --- a/lua/nvim-tree/watcher.lua +++ b/lua/nvim-tree/watcher.lua @@ -99,6 +99,8 @@ function Event:destroy(message) end Event._events[self._path] = nil + + self.destroyed = true end function Watcher:new(path, files, callback, data) @@ -139,6 +141,8 @@ function Watcher:destroy() self._event:remove(self._listener) utils.array_remove(Watcher._watchers, self) + + self.destroyed = true end M.Watcher = Watcher