Skip to content

Commit 697a42b

Browse files
committed
perf(#3257): remove watch setup
1 parent e5cb2a0 commit 697a42b

2 files changed

Lines changed: 20 additions & 26 deletions

File tree

lua/nvim-tree.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ function M.setup(config_user)
286286
end
287287

288288
require("nvim-tree.appearance").setup()
289-
require("nvim-tree.explorer.watch").setup(config.g)
290289
require("nvim-tree.view").setup(config.g)
291290
require("nvim-tree.renderer.components").setup(config.g)
292291

lua/nvim-tree/explorer/watch.lua

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ local notify = require("nvim-tree.notify")
55
local config = require("nvim-tree.config")
66
local Watcher = require("nvim-tree.watcher").Watcher
77

8-
local M = {
9-
config = {},
10-
uid = 0,
11-
}
8+
local M = {}
9+
10+
-- monotonically increasing, unique
11+
local uid = 0
1212

1313
---@param path string
1414
---@return boolean
@@ -48,7 +48,7 @@ local function is_folder_ignored(path)
4848

4949
---Return true when p matches an entry in dirs, escaping for windows
5050
---@param p string absolute path
51-
---@param dirs string[] absolute or relative
51+
---@param dirs string[] regexes
5252
---@return boolean
5353
local function matches_dirs(p, dirs)
5454
for _, dir in ipairs(dirs) do
@@ -63,22 +63,22 @@ local function is_folder_ignored(path)
6363
return false
6464
end
6565

66-
if type(M.config.filesystem_watchers.ignore_dirs) == "table" then
67-
if matches_dirs(path, M.config.filesystem_watchers.ignore_dirs) then
66+
if type(config.g.filesystem_watchers.ignore_dirs) == "table" then
67+
if matches_dirs(path, config.g.filesystem_watchers.ignore_dirs --[[@as string[] ]]) then
6868
return true
6969
end
70-
elseif type(M.config.filesystem_watchers.ignore_dirs) == "function" then
71-
if M.config.filesystem_watchers.ignore_dirs(path) then
70+
elseif type(config.g.filesystem_watchers.ignore_dirs) == "function" then
71+
if config.g.filesystem_watchers.ignore_dirs(path) then
7272
return true
7373
end
7474
end
7575

76-
if type(M.config.filesystem_watchers.whitelist_dirs) == "table" and #M.config.filesystem_watchers.whitelist_dirs > 0 then
77-
if not matches_dirs(path, M.config.filesystem_watchers.whitelist_dirs) then
76+
if type(config.g.filesystem_watchers.whitelist_dirs) == "table" and #config.g.filesystem_watchers.whitelist_dirs > 0 then
77+
if not matches_dirs(path, config.g.filesystem_watchers.whitelist_dirs --[[@as string[] ]]) then
7878
return true
7979
end
80-
elseif type(M.config.filesystem_watchers.whitelist_dirs) == "function" then
81-
if not M.config.filesystem_watchers.whitelist_dirs(path) then
80+
elseif type(config.g.filesystem_watchers.whitelist_dirs) == "function" then
81+
if not config.g.filesystem_watchers.whitelist_dirs(path) then
8282
return true
8383
end
8484
end
@@ -89,7 +89,7 @@ end
8989
---@param node DirectoryNode
9090
---@return Watcher|nil
9191
function M.create_watcher(node)
92-
if not M.config.filesystem_watchers.enable or type(node) ~= "table" then
92+
if not config.g.filesystem_watchers.enable or type(node) ~= "table" then
9393
return nil
9494
end
9595

@@ -106,18 +106,18 @@ function M.create_watcher(node)
106106
watcher.data.outstanding_events = watcher.data.outstanding_events + 1
107107

108108
-- disable watcher when outstanding exceeds max
109-
if M.config.filesystem_watchers.max_events > 0 and watcher.data.outstanding_events > M.config.filesystem_watchers.max_events then
109+
if config.g.filesystem_watchers.max_events > 0 and watcher.data.outstanding_events > config.g.filesystem_watchers.max_events then
110110
notify.error(string.format(
111111
"Observed %d consecutive file system events with interval < %dms, exceeding filesystem_watchers.max_events=%s. Disabling watcher for directory '%s'. Consider adding this directory to filesystem_watchers.ignore_dirs",
112112
watcher.data.outstanding_events,
113-
M.config.filesystem_watchers.debounce_delay,
114-
M.config.filesystem_watchers.max_events,
113+
config.g.filesystem_watchers.debounce_delay,
114+
config.g.filesystem_watchers.max_events,
115115
node.absolute_path
116116
))
117117
node:destroy_watcher()
118118
end
119119

120-
utils.debounce(watcher.data.context, M.config.filesystem_watchers.debounce_delay, function()
120+
utils.debounce(watcher.data.context, config.g.filesystem_watchers.debounce_delay, function()
121121
if watcher.destroyed then
122122
return
123123
end
@@ -134,20 +134,15 @@ function M.create_watcher(node)
134134
end)
135135
end
136136

137-
M.uid = M.uid + 1
137+
uid = uid + 1
138138
return Watcher:create({
139139
path = path,
140140
callback = callback,
141141
data = {
142-
context = "explorer:watch:" .. path .. ":" .. M.uid,
142+
context = "explorer:watch:" .. path .. ":" .. uid,
143143
outstanding_events = 0, -- unprocessed events that have not been debounced
144144
}
145145
})
146146
end
147147

148-
function M.setup(opts)
149-
M.config.filesystem_watchers = opts.filesystem_watchers
150-
M.uid = 0
151-
end
152-
153148
return M

0 commit comments

Comments
 (0)