feat(explorer): add filesystem watchers (#1304)

* feat(explorer): add experimental watchers

This commit introduces watchers to update the tree.
This behavior is introduced behind an "filesystem_watchers" option
which should prevent instabilities.
It will become the default at some point.

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Kiyan
2022-06-05 12:39:39 +02:00
committed by GitHub
parent a5793f1edb
commit b0d27c09b6
19 changed files with 379 additions and 38 deletions

View File

@@ -1,6 +1,7 @@
local uv = vim.loop
local git = require "nvim-tree.git"
local watch = require "nvim-tree.explorer.watch"
local M = {}
@@ -15,6 +16,8 @@ function Explorer.new(cwd)
local explorer = setmetatable({
absolute_path = cwd,
nodes = {},
watcher = watch.create_watcher(cwd),
open = true,
}, Explorer)
explorer:_load(explorer)
return explorer
@@ -30,11 +33,30 @@ function Explorer:expand(node)
self:_load(node)
end
function Explorer.clear_watchers_for(root_node)
local function iterate(node)
if node.watcher then
node.watcher:stop()
for _, child in pairs(node.nodes) do
if child.watcher then
iterate(child)
end
end
end
end
iterate(root_node)
end
function Explorer:_clear_watchers()
Explorer.clear_watchers_for(self)
end
function M.setup(opts)
require("nvim-tree.explorer.explore").setup(opts)
require("nvim-tree.explorer.filters").setup(opts)
require("nvim-tree.explorer.sorters").setup(opts)
require("nvim-tree.explorer.reload").setup(opts)
require("nvim-tree.explorer.watch").setup(opts)
end
M.Explorer = Explorer