Skip to content

Commit c3d9b17

Browse files
authored
docs: notify users with a fs.inotify.max_user_watches message on EMFILE event (#3028)
* docs: notify users with a fs.inotify.max_user_watches message on EMFILE event * type safety for newly created vim.v.event type
1 parent db8d7ac commit c3d9b17

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lua/nvim-tree/actions/root/change-dir.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
---@param new_tabpage integer
2626
---@return boolean
2727
local function is_window_event(new_tabpage)
28-
local is_event_scope_window = vim.v.event.scope == "window" or vim.v.event.changed_window
28+
local is_event_scope_window = vim.v.event.scope == "window" or vim.v.event.changed_window or false
2929
return is_event_scope_window and new_tabpage == M.current_tab
3030
end
3131

lua/nvim-tree/watcher.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ local utils = require("nvim-tree.utils")
44

55
local 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+
79
local 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

Comments
 (0)