watcher.py¶
clew/mcp_server/watcher.py
OS file-change events that wake the server's refresh loop the moment a file is saved.
sync
None clew.mcp_server.watcher.RepoWatcher.sync(self, set[str] roots)
Watch exactly these roots: schedule new ones, unschedule dropped ones.
Source · 23 lines
def sync(self, roots: set[str]) -> None:
"""NEVER RAISES: a root that cannot be watched is logged and left to the interval sweep.
@brief Reconcile the scheduled watches.
@return None.
@version 1
"""
observer = self._ensure_observer()
if observer is None:
return
for root in sorted(set(self._watches) - roots):
observer.unschedule(self._watches.pop(root))
for root in sorted(roots - set(self._watches)):
try:
self._watches[root] = observer.schedule(self._handler(), root, recursive=True)
except Exception as exc: # inotify limits, vanished directory, unsupported fs
logger.warning(
"file watch on %s could not start (%s); its index is kept current by the "
"interval sweep instead",
root,
exc,
)