Skip to content
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 into
mainfrom
peterguy/vscode-bring-back-matched-lines-in-search-results
Jun 27, 2024
Merged

fix(search): VSCode Search extension: bring back matched lines in search results. #63524
peterguy merged 3 commits into
mainfrom
peterguy/vscode-bring-back-matched-lines-in-search-results

Conversation

@peterguy

Copy link
Copy Markdown
Contributor

Due to changes in the code base, the search extension code when run from main shows 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:
Screenshot 2024-06-27 at 10 04 37

Running from main:
Screenshot 2024-06-27 at 10 11 17

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

git switch peterguy/vscode-bring-back-matched-lines-in-search-results
cd client/vscode
pnpm run build

Run

  • Launch extension in VSCode: open the Run and Debug sidebar view in VS Code, then select Launch VS Code Extension from the dropdown menu.
  • Run a search using the search bar.
  • See that the results contain matched lines in the files and not just a list of file names. Compare to the currently-deployed extension - the search results should look generally the same.

peterguy added 3 commits June 26, 2024 20:22
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.
@cla-bot cla-bot Bot added the cla-signed label 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`
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added handling of line matches to the shared code.

Comment on lines +300 to +305
function matchesToMatchGroups(result: ContentMatch): MatchGroup[] {
return [
...(result.lineMatches?.map(lineToMatchGroup) ?? []),
...(result.chunkMatches?.map(chunkToMatchGroup) ?? []),
]
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@peterguy peterguy enabled auto-merge (squash) June 27, 2024 18:07

@camdencheek camdencheek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great -- thanks for the fix!

@peterguy peterguy merged commit 72c00d3 into main Jun 27, 2024
@peterguy peterguy deleted the peterguy/vscode-bring-back-matched-lines-in-search-results branch June 27, 2024 19:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants