Repository navigation
fix: drop blank separator between context-free search matches - #818
Merged
Merged
Conversation
search_file_contents put a blank line between every match, which #766 flagged as waste alongside the two-line-per-match layout that #774 already removed. Context-free matches now join with a single newline. Layout is also now decided by the contextLines argument rather than by sniffing each match's content for a newline. contextLines applies to the whole call, so it is the accurate signal; sniffing misread any context block that collapsed to one line, which happens on single-line files and when truncation drops every newline, rendering them with the exact-match header and a doubled line number.
12 of 13 tasks
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.
Follow-up to #774, which resolved #766. Picks up the two points raised in that PR's review.
Changes
Drop the blank separator between context-free matches. #774 collapsed each match from two lines to one but kept
.join('\n\n'), so a blank line still sat between every match. #766 flagged that separator alongside the layout, so this lands the rest of it. Context blocks keep their blank-line separation, where it genuinely aids legibility.Decide layout from
contextLinesrather than sniffing content for a newline.contextLinesapplies to the whole call, so it is the accurate signal. Sniffing misread any context block that collapsed to a single line, which happens on single-line files and whenever truncation drops every newline from the block. Those rendered with the exact-match header and a doubled line number:Measured
Real 30-match search (
useStateacross*.tsx):Test plan
pnpm run test:ava source/tools/search-file-contents.spec.tsx— 58 passtest:lint,test:types,test:format— cleanNote
The estimate in #766 of 3-4 tokens per match was mine and it was optimistic. The real figure is closer to 2 characters per match. The win is free and lossless but small, so it is not worth sizing future work off that number.