chore(setup): make setup idempotent (#1340)

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Kiyan
2022-06-26 12:14:03 +02:00
committed by GitHub
parent 0c13bd76a8
commit e6c1b4cd5b
7 changed files with 293 additions and 269 deletions

View File

@@ -3,14 +3,14 @@ local uv = vim.loop
local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local M = {}
local Watcher = {
local M = {
_watchers = {},
}
local Watcher = {}
Watcher.__index = Watcher
function Watcher.new(opts)
for _, existing in ipairs(Watcher._watchers) do
for _, existing in ipairs(M._watchers) do
if existing._opts.absolute_path == opts.absolute_path then
log.line("watcher", "Watcher:new using existing '%s'", opts.absolute_path)
return existing
@@ -25,7 +25,7 @@ function Watcher.new(opts)
watcher = watcher:start()
table.insert(Watcher._watchers, watcher)
table.insert(M._watchers, watcher)
return watcher
end
@@ -74,4 +74,11 @@ end
M.Watcher = Watcher
function M.purge_watchers()
for _, watcher in pairs(M._watchers) do
watcher:stop()
end
M._watchers = {}
end
return M