chore(watchers): refactor events and make debouncer safe

- fs poll -> fs events
- make debouncer safe and fix diagnostics events
This commit is contained in:
Alexander Courtis
2022-07-17 16:50:24 +10:00
committed by GitHub
parent 26512c369f
commit 06e48c29c4
12 changed files with 155 additions and 82 deletions

View File

@@ -43,6 +43,16 @@ function M.update_git_status(node, parent_ignored, status)
end
end
function M.node_destroy(node)
if not node then
return
end
if node.watcher then
node.watcher:destroy()
end
end
function M.setup(opts)
M.config = {
git = opts.git,

View File

@@ -2,6 +2,7 @@ local uv = vim.loop
local git = require "nvim-tree.git"
local watch = require "nvim-tree.explorer.watch"
local common = require "nvim-tree.explorer.common"
local M = {}
@@ -33,22 +34,16 @@ function Explorer:expand(node)
self:_load(node)
end
function Explorer.clear_watchers_for(root_node)
function Explorer:destroy()
local function iterate(node)
if node.watcher then
node.watcher:stop()
common.node_destroy(node)
if node.nodes then
for _, child in pairs(node.nodes) do
if child.watcher then
iterate(child)
end
iterate(child)
end
end
end
iterate(root_node)
end
function Explorer:_clear_watchers()
Explorer.clear_watchers_for(self)
iterate(self)
end
function M.setup(opts)

View File

@@ -69,7 +69,12 @@ function M.reload(node, status)
node.nodes = vim.tbl_map(
update_status(nodes_by_path, node_ignored, status),
vim.tbl_filter(function(n)
return child_names[n.absolute_path]
if child_names[n.absolute_path] then
return child_names[n.absolute_path]
else
common.node_destroy(n)
return nil
end
end, node.nodes)
)

View File

@@ -46,7 +46,7 @@ function M.create_watcher(absolute_path)
end
log.line("watcher", "node start '%s'", absolute_path)
Watcher.new {
return Watcher.new {
absolute_path = absolute_path,
interval = M.interval,
on_event = function(opts)