Skip to content

Add --watch/-w flag to re-run analysis on file changes - #52

Merged
coldhighsun merged 2 commits into
mainfrom
feature/watch-mode
Sep 12, 2026
Merged

Add --watch/-w flag to re-run analysis on file changes#52
coldhighsun merged 2 commits into
mainfrom
feature/watch-mode

Conversation

@coldhighsun

Copy link
Copy Markdown
Owner

Summary

  • Add --watch/-w flag: watches the scanned path with FileSystemWatcher, debounces bursts of changes (~400ms), and re-scans/re-analyzes on each settled change, refreshing the same live table (Spectre.Console Live) until Ctrl+C.
  • Table format only; --watch is rejected together with --git-hash, --list-file, or --baseline since those aren't live filesystem sources.
  • Docs (CLAUDE.md, README.md EN/中文) updated with the new option.

Test plan

  • dotnet build Sloc.slnx
  • dotnet test Sloc.slnx
  • Manual: run sloc <dir> --watch, edit a file under <dir>, confirm the table refreshes within ~1s; press Ctrl+C to confirm clean exit
  • Manual: confirm --watch combined with --git-hash, --list-file, --baseline, or a non-Table --format fails with a clear error

Generated by Claude Code

Watches the scanned path with FileSystemWatcher, debounces bursts of
changes (~400ms), and re-scans/re-analyzes on each settled change,
refreshing the same Spectre.Console live table until Ctrl+C. Table
format only; rejected together with --git-hash, --list-file, or
--baseline since those aren't live filesystem sources.
- Ctrl+C now wakes the debounce wait immediately via a signaled
  ManualResetEventSlim instead of waiting out a plain Thread.Sleep.
- Extract the scan-then-analyze-then-merge-then-dedup logic shared by
  the one-shot run and each watch pass into a single AnalyzeFiles
  helper, so the two paths can't drift apart.
- Filter out FileSystemWatcher events under well-known build/VCS/
  package directories (bin, obj, .git, node_modules, etc.) so editors
  and build output don't trigger constant rescans.
@coldhighsun
coldhighsun merged commit f84476e into main Sep 12, 2026
9 checks passed
@coldhighsun
coldhighsun deleted the feature/watch-mode branch September 12, 2026 15:25
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.

1 participant