feat(watch): add on_error callback

Problem: Watcher failures are reported inconsistently, and callers
cannot detect when a watcher is no longer usable.

Solution: Route startup and event failures and unexpected inotifywait
exits through an optional on_error callback. Log to nvim-watch.log by
default. Ignore disappearing child directories and exits caused by
cancellation. Let LSP log failures and notify once per message, using
INFO for missing roots and ERROR otherwise, without interrupting
registration.

AI-assisted
This commit is contained in:
Lewis Russell
2026-09-07 16:21:52 +01:00
committed by Lewis Russell
parent 318ea4de21
commit efdd73c096
5 changed files with 196 additions and 66 deletions

View File

@@ -209,9 +209,11 @@ end
--- @param name string Plugin name, e.g. "zip".
--- @param msg string
--- @param level? integer Level from |vim.log.levels|. Defaults to ERROR.
function M.notify(name, msg, level)
--- @param once? boolean Only show the message once.
function M.notify(name, msg, level, once)
vim.schedule(function()
vim.notify(('%s: %s'):format(name, msg), level or vim.log.levels.ERROR)
local notify = once and vim.notify_once or vim.notify
notify(('%s: %s'):format(name, msg), level or vim.log.levels.ERROR)
end)
end