@@ -5,10 +5,10 @@ local notify = require("nvim-tree.notify")
55local config = require (" nvim-tree.config" )
66local 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
8989--- @param node DirectoryNode
9090--- @return Watcher | nil
9191function 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 })
146146end
147147
148- function M .setup (opts )
149- M .config .filesystem_watchers = opts .filesystem_watchers
150- M .uid = 0
151- end
152-
153148return M
0 commit comments