You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add --match-context N for same-line excerpts - #228
↑ Added a regression test for replacement-introduced CRLF and verified the expected excerpt boundary. ↑ All three match-context integration tests and workspace Clippy with warnings denied pass on Windows. ↑ Formatting and whitespace checks pass. ↓ CI for this pushed revision has not yet started or been inspected.
Diagnosis confidence
10/10
↑ Reproduced the reported hit-hit/X\r\nY case before the change; the right-context scan admitted CR before LF. ↑ The regression test fails before the fix and passes after excluding CR when followed by LF.
Evidence fit
10/10
↑ The reproducer uses the exact input, match-context radius, and CRLF replacement from the review comment; output now omits the CR at the excerpt boundary.
Coding agents need to see context around matches. On a long line of minified JavaScript, a few characters around a function name can show how it’s called. --match-context N extends -o to print up to N Unicode characters on either side of a match.
The flag implies -o. The matcher searches for the original expression and the output code extends the excerpt to the requested width or the line boundary. Highlighting, columns, and byte offsets still identify the match. A radius of zero behaves like -o. The CLI and server use the same excerpt logic.
Firefox benchmark
On Firefox, plain -o and --match-context 30 returned the same 10 match locations from 51 candidate files. The regex workaround, .{0,30}(?:pattern).{0,30}, produced a MatchAll plan and searched 469,879 of 470,722 indexed files. Firefox revision
Indexed search
Median of three runs
Plain -o, patched build
0.43 s
--match-context 30, patched build
0.31 s
Regex workaround, released tgrep 1.2.8
105 s
Testing
Tested on Apple Silicon with macOS 26.6.2 and Rust 1.98.0.
Check
Result
cargo fmt --all --check
Passed.
cargo test --locked -p tgrep-cli --test ripgrep_compat match_context
Both tests passed. They check Unicode excerpts, match positions, highlighting, replacements, JSON output, and indexed candidate counts.
Clippy across all workspace targets with managed-test-hooks
Completed with one needless_return warning in tgrep-core/src/managed/authentication_native.rs:89. The documented -D warnings check failed on that warning. The same failure reproduced on unmodified main.
Workspace tests with default features
1,532 passed, 1 failed, 4 ignored. A daemon polling test called testing.reconcile-timer, which requires test hooks. The same failure reproduced on unmodified main.
Workspace tests with managed-test-hooks
1,598 passed, 1 failed, 7 ignored. The managed collection crash-recovery test failed during the suite and passed when rerun in isolation.
Maintainer follow-ups
Clippy fixes for Rust 1.100 (be752d8).
--match-context N > 0 now prints context around an empty -U --replace replacement; plain -o still prints nothing (1fa1a9c).
Adds --match-context N to show same-line Unicode context around each match without changing the search expression or indexed query plan, addressing #227.
Changes:
Adds the CLI option and shared excerpt rendering for local and server searches.
Extends server protocols with capability checks for compatible fallback.
Documents the flag and adds coverage for excerpts, positions, replacements, JSON, and indexed candidate counts.
File
Description
tgrep-cli/tests/shared_daemon.rs
Adds shared-daemon excerpt coverage.
tgrep-cli/tests/ripgrep_compat.rs
Tests rendering, backend consistency, and capability fallback.
tgrep-cli/src/serve/shared/server.rs
Validates the option and advertises shared-v1 support.
tgrep-cli/src/serve/shared/managed.rs
Advertises managed shared-v2 support.
tgrep-cli/src/serve.rs
Parses the radius and configures server matching.
tgrep-cli/src/search.rs
Passes rendering options and checks server support.
tgrep-cli/src/matching.rs
Implements Unicode-aware excerpts and highlighting spans.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Empty replacements are dropped with positive match context, causing valid surrounding text to disappear from output.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Show zero-width replacements when context radius is positive
tgrep-cli/src/matching.rs:1468
With --match-context=1 -U -r '' 'ab\ncd', searching xab\ncdz\n produces no visible output instead of xz. piece drops the empty replacement before this excerpt code runs, even though surrounding text is available. Admit zero-width replacements on their rewritten line when the radius is positive, while preserving radius-zero behavior.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Empty-string replacements of multiline matches incorrectly drop the context anchor, causing positive-radius match context to print nothing instead of the expected surrounding text.
Return platform capacity checks and stale merge results directly without changing their behavior.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Empty multiline replacements suppress surrounding context when the context radius is positive, making their behavior inconsistent with single-line replacements.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Empty multiline replacements are rejected before context extraction, causing --match-context=1 to emit no excerpt instead of the expected surrounding text.
With --match-context N > 0, an empty -U --replace replacement now anchors an
excerpt on the rewritten line that contains its position, so
`--match-context=1 -U -r '' 'ab\ncd'` on "xab\ncdz" prints "xz" instead of
nothing. Plain -o (radius 0) still prints nothing for empty replacements.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The right-context loop includes the CR from a replacement-introduced CRLF, causing excerpts to copy part of a line terminator instead of stopping before it.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human review is needed to assess the time and memory regression from collecting every match span for count and files-only requests with match context, even though those modes never render excerpts.
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
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.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
0fa212690b6a04fae7962414afaaa8810b2729e3↑ All three match-context integration tests and workspace Clippy with warnings denied pass on Windows.
↑ Formatting and whitespace checks pass.
↓ CI for this pushed revision has not yet started or been inspected.
hit-hit/X\r\nYcase before the change; the right-context scan admitted CR before LF.↑ The regression test fails before the fix and passes after excluding CR when followed by LF.
Coding agents need to see context around matches. On a long line of minified JavaScript, a few characters around a function name can show how it’s called.
--match-context Nextends-oto print up to N Unicode characters on either side of a match.The flag implies
-o. The matcher searches for the original expression and the output code extends the excerpt to the requested width or the line boundary. Highlighting, columns, and byte offsets still identify the match. A radius of zero behaves like-o. The CLI and server use the same excerpt logic.Firefox benchmark
On Firefox, plain
-oand--match-context 30returned the same 10 match locations from 51 candidate files. The regex workaround,.{0,30}(?:pattern).{0,30}, produced aMatchAllplan and searched 469,879 of 470,722 indexed files. Firefox revision-o, patched build--match-context 30, patched buildTesting
Tested on Apple Silicon with macOS 26.6.2 and Rust 1.98.0.
cargo fmt --all --checkcargo test --locked -p tgrep-cli --test ripgrep_compat match_contextmanaged-test-hooksneedless_returnwarning intgrep-core/src/managed/authentication_native.rs:89. The documented-D warningscheck failed on that warning. The same failure reproduced on unmodifiedmain.testing.reconcile-timer, which requires test hooks. The same failure reproduced on unmodifiedmain.managed-test-hooksMaintainer follow-ups
be752d8).--match-context N > 0now prints context around an empty-U --replacereplacement; plain-ostill prints nothing (1fa1a9c).f004148).Closes #227