fix(grep): scope the search to the PATH argument#48
Merged
Conversation
`aden grep <pat> <PATH>` used PATH only to locate the project root, then always discovered from that root — so `grep <pat> some/file.rs` silently searched the WHOLE repo (and could dump megabytes when it matched minified asset lines). Reported while testing the installed CLI: scoping to one file returned 787 hits across 8 files including a vendored .min.js. Scope discovery to PATH: a file searches just that file, a subdirectory searches under it, the project root searches everything. Symbol attribution still keys off the project root, so hits keep their enclosing-symbol tags. Adds discover_source_files_scoped(scope, root) (discover_source_files is now a thin wrapper) plus a unit test asserting a scoped walk sees only its subtree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the grep PATH-scoping bug I flagged in #47 and reproduced while testing the installed CLI.
aden grep <pat> <PATH>used PATH only to locate the project root, then always discovered files from that root. Sogrep <pat> some/file.rssilently searched the whole repo — scoping to one file returned 787 hits across 8 files including a vendored3d-force-graph.min.js, and could dump megabytes when it matched minified asset lines.Now discovery is scoped to PATH:
.) searches everything (unchanged).Symbol attribution still keys off the project root, so hits keep their enclosing-symbol tags.
Implementation:
discover_source_filesis now a thin wrapper over a newdiscover_source_files_scoped(scope, root)(ignore rules still resolve relative toroot). Single-file PATH is handled directly incmd_grep.Verified end-to-end on the built binary:
grep "fn " crates/aden-cli/src/main.rs→ 2 hits in 1 file (was 787 across 8)grep "fn " crates/aden-store→ 87 hits, all under aden-storegrep "fn " .→ 10184 hits, repo-wide (unchanged)Test plan
cargo test -p aden-cligreen (newdiscover_source_files_scoped_narrows_to_subtree)cargo clippy --workspacecleancargo fmt --allappliedLicense checklist