@@ -4,6 +4,8 @@ local utils = require("nvim-tree.utils")
44
55local Class = require (" nvim-tree.classic" )
66
7+ local MESSAGE_EMFILE = " fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting"
8+
79local FS_EVENT_FLAGS = {
810 -- inotify or equivalent will be used; fallback to stat has not yet been implemented
911 stat = false ,
@@ -75,6 +77,18 @@ function Event:start()
7577 local event_cb = vim .schedule_wrap (function (err , filename )
7678 if err then
7779 log .line (" watcher" , " event_cb '%s' '%s' FAIL : %s" , self .path , filename , err )
80+
81+ -- do nothing if watchers have already been disabled
82+ if not M .config .filesystem_watchers .enable then
83+ return
84+ end
85+
86+ -- EMFILE is catastrophic
87+ if name == " EMFILE" then
88+ M .disable_watchers (MESSAGE_EMFILE )
89+ return
90+ end
91+
7892 local message = string.format (" File system watcher failed (%s) for path %s, halting watcher." , err , self .path )
7993 if err == " EPERM" and (utils .is_windows or utils .is_wsl ) then
8094 -- on directory removal windows will cascade the filesystem events out of order
@@ -94,7 +108,7 @@ function Event:start()
94108 rc , _ , name = self .fs_event :start (self .path , FS_EVENT_FLAGS , event_cb )
95109 if rc ~= 0 then
96110 if name == " EMFILE" then
97- M .disable_watchers (" fs.inotify.max_user_watches exceeded, see https://github.com/nvim-tree/nvim-tree.lua/wiki/Troubleshooting " )
111+ M .disable_watchers (MESSAGE_EMFILE )
98112 else
99113 notify .warn (string.format (" Could not start the fs_event watcher for path %s : %s" , self .path , name ))
100114 end
0 commit comments