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

Method handleChange

src/sync/watcher.ts:649–707  ·  view source on GitHub ↗

* Shared change handler for both watch strategies. `rel` is a * project-relative POSIX path. Applies the ignore + source-file filters and, * for a real source change, records it as pending (#403) and schedules a * debounced sync. * * The recursive (macOS/Windows) watcher reports event

(rel: string)

Source from the content-addressed store, hash-verified

647 * — it drops node_modules/dist/.git churn before any sync is scheduled.
648 */
649 private handleChange(rel: string): void {
650 if (!rel || rel === '.' || escapesRoot(rel)) return;
651 // `.git/info/exclude` is otherwise always-ignored with the rest of `.git/`,
652 // but it feeds `buildScopeIgnore` — allow it through as a scope refresh
653 // when the platform delivers the event (recursive watchers may; Linux
654 // per-directory watching does not descend into `.git/`) (#1728).
655 if (rel === '.git/info/exclude') {
656 this.refreshScope(rel);
657 return;
658 }
659 if (this.isAlwaysIgnored(rel)) return;
660 // The two root files the scope matcher is derived from are handled BEFORE
661 // the matcher is consulted: a user `exclude` pattern that happens to cover
662 // them (`*.json`, `.*`) must not be able to hide their own edits (#1590).
663 if (rel === PROJECT_CONFIG_FILENAME || rel === '.gitignore') {
664 this.refreshScope(rel);
665 return;
666 }
667 if (this.ignoreMatcher && this.ignoreMatcher.ignores(rel)) return;
668 // A nested `.gitignore` (an embedded child repo's own rules, #514, or a
669 // subdirectory rule the git-backed full scan honors) is only a scope
670 // change when it sits INSIDE the current scope — checked after the matcher
671 // on purpose, so the thousands of package-local `.gitignore`s an
672 // `npm install` writes under an ignored `node_modules/` never trigger a
673 // rebuild storm.
674 if (rel.endsWith('/.gitignore')) {
675 this.refreshScope(rel);
676 return;
677 }
678 if (!isSourceFile(rel, loadExtensionOverrides(this.projectRoot), this.projectRoot)) {
679 this.maybeScheduleForRemovedDir(rel);
680 return;
681 }
682
683 try {
684 if (this.isFileStateCurrent?.(rel)) {
685 logDebug('Ignoring file event with unchanged indexed metadata', { file: rel });
686 return;
687 }
688 } catch (error) {
689 // The guard is an optimization, never a correctness boundary. If the
690 // stat/DB lookup fails, keep the event so a sync can reconcile it.
691 logDebug('Could not verify file event metadata; treating it as a change', {
692 file: rel,
693 error: String(error),
694 });
695 }
696
697 logDebug('File change detected', { file: rel });
698 if (this.ready) {
699 const now = Date.now();
700 const existing = this.pendingFiles.get(rel);
701 this.pendingFiles.set(rel, {
702 firstSeenMs: existing?.firstSeenMs ?? now,
703 lastSeenMs: now,
704 });
705 }
706 this.scheduleSync();

Callers 2

handleDirEventMethod · 0.95
ingestEventForTestsMethod · 0.95

Calls 11

refreshScopeMethod · 0.95
isAlwaysIgnoredMethod · 0.95
scheduleSyncMethod · 0.95
escapesRootFunction · 0.90
isSourceFileFunction · 0.90
loadExtensionOverridesFunction · 0.90
logDebugFunction · 0.90
ignoresMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected