fix(#1804): do not refresh watched nodes that have been destroyed (deleted)

This commit is contained in:
Alexander Courtis 2022-12-19 14:36:42 +11:00
parent e0cfbbb93d
commit d949af7245
4 changed files with 11 additions and 0 deletions

View File

@ -121,6 +121,7 @@ function M.node_destroy(node)
if node.watcher then
node.watcher:destroy()
node.watcher = nil
end
end

View File

@ -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

View File

@ -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

View File

@ -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