This repository was archived by the owner on Sep 30, 2024. It is now read-only.
fix(search): VSCode Search extension: bring back matched lines in search results. #63524
Merged
peterguy merged 3 commits intoJun 27, 2024
Merged
Conversation
Everything seems to have gone to chunk matches, which do seem to be better, but some clients still call for line matches, so add the ability to map line matches to `MatchGroup`s as well.
Especially, the new `MatchGroup` component. This is the change that actually fixes the display of the matched lines.
peterguy
commented
Jun 27, 2024
Comment on lines
+323
to
+337
| function lineToMatchGroup(line: LineMatch): MatchGroup { | ||
| const matches = line.offsetAndLengths.map(offsetAndLength => ({ | ||
| startLine: line.lineNumber, | ||
| startCharacter: offsetAndLength[0], | ||
| endLine: line.lineNumber, | ||
| endCharacter: offsetAndLength[0] + offsetAndLength[1], | ||
| })) | ||
| return { | ||
| plaintextLines: [line.line], | ||
| highlightedHTMLRows: undefined, // populated lazily | ||
| matches, | ||
| startLine: line.lineNumber, | ||
| endLine: line.lineNumber + 1, // the matches support `endLine` == `startLine`, but MatchGroup requires `endLine` > `startLine` | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Added handling of line matches to the shared code.
peterguy
commented
Jun 27, 2024
Comment on lines
+300
to
+305
| function matchesToMatchGroups(result: ContentMatch): MatchGroup[] { | ||
| return [ | ||
| ...(result.lineMatches?.map(lineToMatchGroup) ?? []), | ||
| ...(result.chunkMatches?.map(chunkToMatchGroup) ?? []), | ||
| ] | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Combine line matches and chunk matches. I expect that there will only ever be one or the other because the search stream toggles between the two using cm=t or cm=f in the query string.
peterguy
commented
Jun 27, 2024
Contributor
Author
There was a problem hiding this comment.
Had to fix FileMatchChildren along the way because its internal MatchGroup and associated usage had not kept up with the rest of the codebase, resulting in NPEs when accessing the position structure.
camdencheek
approved these changes
Jun 27, 2024
camdencheek
left a comment
Member
There was a problem hiding this comment.
Looks great -- thanks for the fix!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Due to changes in the code base, the search extension code when run from
mainshows file names only in the search results page - no matches in the files. This is a regression from the behavior in the deployed extension.Deployed extension:

Running from

main:Turns out the reason is because some shared code expects chunk matches, while the search queries were all returning line matches.
Added support for line matches in the shared code, and then fixed an issue with the search results display not keeping up with
MatchGroups.Test plan
Build and run locally.
Build
Run
Run and Debugsidebar view in VS Code, then selectLaunch VS Code Extensionfrom the dropdown menu.