feat(watcher): debounce FS watchers
This commit is contained in:
@@ -22,6 +22,21 @@ local function is_git(path)
|
||||
return path:match "%.git$" ~= nil or path:match(utils.path_add_trailing ".git") ~= nil
|
||||
end
|
||||
|
||||
local function refresh_path(path)
|
||||
log.line("watcher", "node event executing '%s'", path)
|
||||
local n = utils.get_node_from_path(path)
|
||||
if not n then
|
||||
return
|
||||
end
|
||||
|
||||
local node = utils.get_parent_of_group(n)
|
||||
local project_root, project = reload_and_get_git_project(path)
|
||||
require("nvim-tree.explorer.reload").reload(node, project)
|
||||
update_parent_statuses(node, project, project_root)
|
||||
|
||||
require("nvim-tree.renderer").draw()
|
||||
end
|
||||
|
||||
function M.create_watcher(absolute_path)
|
||||
if not M.enabled then
|
||||
return nil
|
||||
@@ -34,19 +49,11 @@ function M.create_watcher(absolute_path)
|
||||
Watcher.new {
|
||||
absolute_path = absolute_path,
|
||||
interval = M.interval,
|
||||
on_event = function(path)
|
||||
local n = utils.get_node_from_path(absolute_path)
|
||||
if not n then
|
||||
return
|
||||
end
|
||||
log.line("watcher", "node event '%s'", path)
|
||||
|
||||
local node = utils.get_parent_of_group(n)
|
||||
local project_root, project = reload_and_get_git_project(path)
|
||||
require("nvim-tree.explorer.reload").reload(node, project)
|
||||
update_parent_statuses(node, project, project_root)
|
||||
|
||||
require("nvim-tree.renderer").draw()
|
||||
on_event = function(opts)
|
||||
log.line("watcher", "node event scheduled '%s'", opts.absolute_path)
|
||||
utils.debounce("explorer:watch:" .. opts.absolute_path, M.debounce_delay, function()
|
||||
refresh_path(opts.absolute_path)
|
||||
end)
|
||||
end,
|
||||
}
|
||||
end
|
||||
@@ -54,6 +61,7 @@ end
|
||||
function M.setup(opts)
|
||||
M.enabled = opts.filesystem_watchers.enable
|
||||
M.interval = opts.filesystem_watchers.interval
|
||||
M.debounce_delay = opts.filesystem_watchers.debounce_delay
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user