Skip to content

feat(watcher): tear down watcher on failue, warning the user #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lua/nvim-tree/watcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function Event:start()

local event_cb = vim.schedule_wrap(function(err, filename)
if err then
log.line("watcher", "event_cb for %s fail : %s", self._path, err)
log.line("watcher", "event_cb '%s' '%s' FAIL : %s", self._path, filename, err)
self:destroy(string.format("File system watcher failed (%s) for path %s, halting watcher.", err, self._path))
else
log.line("watcher", "event_cb '%s' '%s'", self._path, filename)
for _, listener in ipairs(self._listeners) do
Expand Down Expand Up @@ -82,10 +83,14 @@ function Event:remove(listener)
end
end

function Event:destroy()
function Event:destroy(message)
log.line("watcher", "Event:destroy '%s'", self._path)

if self._fs_event then
if message then
utils.notify.warn(message)
end

local rc, _, name = self._fs_event:stop()
if rc ~= 0 then
utils.notify.warn(string.format("Could not stop the fs_event watcher for path %s : %s", self._path, name))
Expand Down