Repository navigation
Fix whole-word literal search skipping overlapping valid matches - #344811
Draft
cloudspeedapps-coder wants to merge 10 commits into
Draft
cloudspeedapps-coder wants to merge 10 commits into
cloudspeedapps-coder wants to merge 10 commits into
Conversation
Refactor search logic to improve match handling and add findNextWordStart function for better word boundary detection.
Refactor search logic to improve match finding efficiency.
Added tests for whole-word search functionality, including regex and edge cases.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The search retry logic can loop forever on rejected non-global empty matches and perform quadratic rescanning after whole-word boundary failures, potentially hanging Find.
2 open issues
What changed in this PR
Fixes whole-word search missing valid matches that overlap rejected candidates, addressing #291591 across VS Code’s literal and regex search paths.
Changes:
- Retry rejected candidates at the next possible word boundary while preserving non-overlapping accepted matches.
- Share Unicode-aware advancement logic between text-model and piece-tree searches.
- Add regression and control tests for overlaps, end-of-text matches, surrogate pairs, and termination.
| File | Description |
|---|---|
src/vs/editor/test/common/model/textModelSearch.test.ts |
Adds regression and control coverage across search modes and buffer paths. |
src/vs/editor/common/model/textModelSearch.ts |
Adds the shared boundary helper and updates literal and regex retries. |
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeBase.ts |
Applies boundary-aware retries to the piece-tree literal-search fast path. |
Review effort: Balanced
|
|
||
| // Retry inside rejected candidates, including those that end at the end of the text. | ||
| // Skip to a possible word boundary to avoid repeatedly scanning the same long word. | ||
| this._searchRegex.lastIndex = findNextWordStart(this._wordSeparators, text, textLength, matchStartIndex); |
|
|
||
| // Retry inside rejected candidates, including those that end at the end of the text. | ||
| // Skip to a possible word boundary to avoid repeatedly scanning the same long word. | ||
| this._searchRegex.lastIndex = findNextWordStart(this._wordSeparators, text, textLength, matchStartIndex); |
cloudspeedapps-coder
left a comment
Author
There was a problem hiding this comment.
Re-produced this bug and here are the fixes.
Author
|
@microsoft-github-policy-service agree company="CloudSpeed LLC" |
This branch has not been deployed
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 #291591.
Searching for
aa-aawith Match Whole Word enabled and regex mode off misses the trailingaa-aainxaa-aa-aa. The first candidate begins inside a word and is rejected, but search resumes after that entire candidate, skipping a valid overlapping start. Resume at the next possible word boundary after rejected literal candidates in both literal fast paths and the regex engine used internally for case-insensitive literal search and capture results. Accepted matches retain their existing non-overlapping behavior.SearchData.isLiteralSearchcarries the user's search mode into each Searcher. Overlap retries apply only to literal-text searches. User-entered regular expressions retain their prior behavior of advancing past rejected candidates. This avoids introducing repeated suffix scans for patterns such asa.*bon'a '.repeat(8000) + 'bx'. This PR does not add overlap support for regex mode or promise bounded execution of arbitrary JavaScript regexes.Non-global, non-sticky regexes terminate after their first match because they ignore
lastIndex. This includes both rejected and accepted empty matches; global and sticky empty matches continue to advance normally.Related work: #326447 is an existing open proposal for this issue. I reviewed that proposal during validation, including its performance and non-global-regex considerations. This draft focuses on literal-text search and does not supersede that contributor's work.
Validation
git diff --checkpasses.npm run build-fast -- --client-only.Environment: Windows ARM64, Node 24.19.0, Chrome browser test runner. The local test base requests Node 24.22.1. Full Electron/native validation and a full TypeScript typecheck were not run. The original issue was reproduced manually in installed VS Code 1.144.0; the patched desktop application has not been manually retested. Browser tests ran on the local checkout; published file contents are verified against that tested checkout while preserving the PR's upstream merges.