Skip to content

fix(watch): reindex only changed files; --filter restricts what is indexed - #584

Merged
ajianaz merged 1 commit into
developfrom
fix/watch-detect-changes
Oct 8, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/watch-detect-changes

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #578

What

  • cora watch / index --watch kept no state: detect_changes returned every source file each tick and the whole project was then incrementally indexed, so --filter only gated whether a cycle fired.
  • The watch loop now keeps an (mtime ns, size) snapshot of watched files (ext, --git-only, --filter, and the session's skip patterns ignore.files/index_skip_files). Each tick diffs it: new/modified files are re-indexed, deleted files are detected and pruned by the same run. Idle ticks do no indexing work. The baseline is taken before the initial index, so the first cycle does not report everything as changed.
  • New minimal index entry point index::index_project_filtered(..., include) / IndexSession::index_matching: an include predicate on the root-relative path. Non-included files are not read/reindexed but still count as present, so their rows are not pruned. index_project_with_skip delegates with None (no behavior change for other callers). IndexSession still owns config/skip patterns/backend.

Why

detect_changes returned every source file on each tick, so --filter was only a trigger gate and every cycle ran a whole-project incremental index (found while smoke-testing #577).

User-visible changes

  • --filter now restricts which files are reindexed, not just which cycles fire; modifying a non-matching file does nothing.
  • Only changed files are reindexed per cycle (Reindexed: N files reflects only those). Flags and banner text unchanged.

Testing

Unit tests in commands/watch.rs: unchanged tree -> empty change set (baseline not all-changed); modified file is the only change; new + deleted detected; --filter ignores non-matching changes; skip patterns respected; end-to-end with a real IndexSession: non-matching change -> nothing indexed, matching change -> exactly 1 file reindexed, deletion pruned only that file.

Smoke test (debug binary, temp CODECORA_HOME/project): watch --filter a.rs, append b.rs -> no output; append a.rs -> Reindexed: 1 files, 3 symbols updated. index --watch: append b.rs -> Reindexed: 1 files; rm a.rs -> pruned.

fmt, clippy -D warnings, cargo test --features tree-sitter all pass.

🤖 Generated with Claude Code

…is indexed

detect_changes returned every source file on every tick and the whole
project was reindexed after a trigger, so --filter only gated whether a
cycle fired. The watch loop now keeps an (mtime, size) snapshot, diffs it
each tick (new/modified/deleted), applies the ext/git-only/--filter/skip
filters, and reindexes only the changed files via a new include predicate
(IndexSession::index_matching). Deletions are pruned by the same run; idle
ticks do no indexing work. Fixes both cora watch and index --watch.

Closes #578

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: ajianaz <ajianaz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(watch): detect_changes returns every source file each cycle; --filter only gates the trigger

1 participant