fix(grep): report honest match counts in header when --max caps output#2522
Open
lesbass wants to merge 1 commit into
Open
fix(grep): report honest match counts in header when --max caps output#2522lesbass wants to merge 1 commit into
lesbass wants to merge 1 commit into
Conversation
e512cc7 to
49d2695
Compare
Author
|
Commit authorship has been corrected: author changed from |
629f496 to
e748cbe
Compare
Author
|
I rebased this PR onto the latest develop branch. Unfortunately, GitHub Actions now requires a maintainer to approve the workflow run for fork PRs after a force push. Could someone approve the run so CI can confirm the change is clean? No code changes — just a rebase to resolve the merge conflict. |
When --max or grep_max_results caps the displayed matches, the header previously reported the raw total match count, misleading users about what was actually shown. Defer the header until after the truncation loop and show two numbers when output is capped: 'N matches (K shown) in M files'. Footer [+N more] remains accurate. Fixes rtk-ai#2436 Co-Authored-By: Paperclip <noreply@paperclip.ing>
e748cbe to
9b1571a
Compare
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.
Fixes #2436
Problem
In
rtk grep, the header line "N matches in M files" reports the raw rg/grepmatch count, even when
--maxorgrep_max_resultscaps the displayed output.For example, with
--max 5the output shows 5 results but the header says"211 matches in 50 files".
Root Cause
The header was constructed before the truncation loop, using the raw parsed
match count (
total_matches). The loop correctly enforces caps, but thealready-written header was oblivious.
Fix
Defer the header until after the truncation loop. When output is capped,
the header now shows two numbers:
211 matches in 50 files:211 matches (5 shown) in 50 files:When output is not capped, the header format is unchanged.
The
[+N more]footer remains accurate.Changes
1 file:
src/cmds/system/grep_cmd.rs— restructure header constructionto occur after the truncation loop, with a conditional format for capped output.
Verification
cargo fmt --all --checkpassesa mechanical restructuring with no logic modifications