MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / watch

Method watch

src/index.ts:988–1010  ·  view source on GitHub ↗

* Start watching for file changes and auto-syncing. * * Uses native OS file events (FSEvents on macOS, inotify on Linux 19+, * ReadDirectoryChangesW on Windows) with debouncing to avoid thrashing. * * @param options - Watch options (debounce delay, callbacks) * @returns true if wat

(options: WatchOptions = {})

Source from the content-addressed store, hash-verified

986 * @returns true if watching started successfully
987 */
988 watch(options: WatchOptions = {}): boolean {
989 if (this.watcher?.isActive()) return true;
990
991 this.watcher = new FileWatcher(
992 this.projectRoot,
993 async (paths?: string[]) => {
994 const result = await this.sync({ paths });
995 // sync() returns this exact zero-shape iff it failed to acquire the
996 // file lock (a real empty sync always has filesChecked > 0 because
997 // scanDirectory ran). Surface that to the watcher as a typed error
998 // so it keeps pendingFiles + reschedules instead of clearing them
999 // (#449).
1000 if (result.filesChecked === 0 && result.durationMs === 0) {
1001 throw new LockUnavailableError();
1002 }
1003 const filesChanged = result.filesAdded + result.filesModified + result.filesRemoved;
1004 return { filesChanged, durationMs: result.durationMs };
1005 },
1006 options
1007 );
1008
1009 return this.watcher.start();
1010 }
1011
1012 /**
1013 * Stop watching for file changes.

Callers 4

startWatchingMethod · 0.80
degradeWatcherFunction · 0.80
watcher.test.tsFile · 0.80

Calls 3

syncMethod · 0.95
isActiveMethod · 0.80
startMethod · 0.65

Tested by 1

degradeWatcherFunction · 0.64