Repository navigation
Fix multiline --count-matches totals across search backends - #192
Merged
Shengyu Fu (shengyfu) merged 2 commits intoOct 11, 2026
Merged
Conversation
Count original per-file regex matches before clipping spans into output lines. Carry authoritative totals through ordinary and shared server responses without requiring --stats, and reject incomplete count metadata before output. Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Count requests still transfer unused span detail, risking oversized shared responses and scan fallback.
1 open finding
What changed in this PR
Fixes multiline --count-matches by using original per-file match totals across local, ordinary-server, and shared-server backends.
Changes:
- Uses authoritative match totals instead of rendered line spans.
- Extends server requests/responses with optional count metadata.
- Adds broad regression coverage and documentation.
| File | Description |
|---|---|
README.md |
Documents multiline counting and fallback behavior. |
tgrep-cli/src/matching.rs |
Returns original regex-match totals. |
tgrep-cli/src/search.rs |
Requests, validates, and renders server totals. |
tgrep-cli/src/serve.rs |
Produces per-file totals without enabling diagnostics. |
tgrep-cli/src/serve/shared/server.rs |
Accepts the shared count option. |
tgrep-cli/tests/ripgrep_compat.rs |
Covers local and ordinary-server behavior. |
tgrep-cli/tests/shared_daemon.rs |
Covers shared-v1 counting. |
tgrep-cli/tests/shared_daemon/managed.rs |
Covers managed shared-v2 counting. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <[email protected]>
Shengyu Fu (shengyfu)
deleted the
shengyfu-fix-multiline-match-counting
branch
October 11, 2026 16:50
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 #188
Change
FileMatchesalready retained original regex-match totals after applying search limits, but--count-matchesreconstructed its count from spans clipped onto individual output lines. Onehello\nworldmatch therefore counted twice. The server client independently made the same mistake.Use the original per-file totals for counting in scan/local-index searches and in ordinary/shared-v1/shared-v2 server responses. An opt-in
count_matchesrequest reuses the existing typedfile_statsmetadata without enabling--statsor index diagnostics. Count RPCs omit unused row spans and columns, without disabling local or server-side collection of all original spans. Preserve the existing-c, inversion, adjacent-match, JSON/Unicode offset, and other rendering behavior.Non-counting requests retain their previous wire shape. Counting never guesses from old response rows: missing, malformed, partial, or duplicate per-file totals are rejected before any count output. Ordinary-server fallback includes the cause; older shared servers can reject the new option and use the existing diagnostic scan fallback. Older ordinary servers that provide totals with
--statsremain usable.Regression coverage
--stats, default and PCRE2 engines, forced scan, local index, ordinary server, and shared v1/v2. Backend diagnostics are required; the shared-v1 query counter also proves service of the requests without stats.-o/--vimgrepcombinations. The existing multiline stats test now asserts the actual count instead of only output parity.The original matcher, scan, ordinary-RPC, and both shared regressions were observed failing before the count fix. The follow-up request regression separately failed before row-detail suppression (
detail=true, expected false). Existing controls remain covered.Validation
Build, Rayon, and test concurrency were bounded to two.
Review follow-up:
9f20f5ab6d1356ffa43aa30bfaa773b1ce4ca83cWindows, Rust 1.98.0:
shared request queue fullin the unchanged runtime-attach fixture; this PR does not bypass that assertion or alter queue limits.Original fix:
6a6440bdcc54f7416e490120738fc211daecf529--statsused the actual server; combinations without--statsexplicitly fell back to the local index. The same verifier rejected the old client in the 12 expected cross-line cases while its 36 controls passed. These frozen-candidate results are not attributed to the follow-up head.No dependencies, lockfiles, versions, release configuration, or index formats changed.