Fix inconsistent syntax highlighting in inline suggest preview#269567
Open
magliocchetti wants to merge 2 commits intomicrosoft:mainfrom
Open
Fix inconsistent syntax highlighting in inline suggest preview#269567magliocchetti wants to merge 2 commits intomicrosoft:mainfrom
magliocchetti wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Fixes microsoft#234963 The syntax highlighting for inline suggestions (ghost text) was inconsistent when scrolling through different completion options. This was particularly noticeable when the cursor was inside string literals or when suggestions had different lengths (e.g., "captures" vs "beginCaptures"). The root cause was that tokenization was performed on the entire modified line (original text + ghost text combined), causing different ghost text content to produce different tokenization results. When tokens were extracted for just the inserted ranges, the context was already inconsistent. This change modifies the tokenization approach in ghostTextView.ts to: - Tokenize each inline text segment independently with proper prefix context - Extract only the tokens for the inserted text portion - Maintain proper tokenization state flow for multi-line completions This ensures consistent syntax highlighting regardless of the ghost text content, as the tokenization context at the insertion point remains stable. Signed-off-by: Giovanni Magliocchetti <giovimag123@gmail.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes inconsistent syntax highlighting in inline suggestion previews (ghost text) by changing how the tokenization is performed. Previously, ghost text segments were tokenized as part of a complete modified line, causing different suggestions to be highlighted inconsistently based on their content.
- Rewrote tokenization logic to process each inline text segment independently with proper prefix context
- Fixed multi-line ghost text tokenization to maintain proper state flow
- Added comprehensive comments explaining the new approach
src/vs/editor/contrib/inlineCompletions/browser/view/ghostText/ghostTextView.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Giovanni Magliocchetti <giovimag123@gmail.com>
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 #234963
Problem
Syntax highlighting for inline suggestions (ghost text) was randomly breaking when scrolling through completion options. Users reported several issues:
Example scenario: In a JSON file with cursor inside empty quotes
"", scrolling through suggestions like"captures"vs"beginCaptures"would produce different syntax highlighting, even though both should be highlighted identically as string content.Root Cause
The tokenization logic in
ghostTextView.tswas tokenizing the entire modified line (original text + ghost text combined):This meant:
Solution
The fix tokenizes each ghost text segment independently, preserving the tokenization context at the insertion point:
Key improvements:
Changes
Modified files:
src/vs/editor/contrib/inlineCompletions/browser/view/ghostText/ghostTextView.tsOffsetRangeimportImpact:
Testing
To test this fix:
Enable settings:
{ "editor.suggest.preview": true, "editor.inlineSuggest.syntaxHighlightingEnabled": true }Create a JSON file with this content:
{ "$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json", "patterns": [ { "" } ] }Place cursor inside the empty quotes (between
"")Press
Ctrl+Spaceto open suggestionsScroll through suggestions like
"captures","beginCaptures", etc.Expected behavior (with fix):
Previous behavior (bug):