Fix escape sequence semantic highlighting#19975
Open
shenglol wants to merge 1 commit into
Open
Conversation
Comment on lines
+297
to
+337
| private static int? TryGetEscapeSequenceLength(string text, int position, int end) | ||
| { | ||
| if (text[position] != '\\' || position + 1 >= end) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| return text[position + 1] switch | ||
| { | ||
| 'n' or 'r' or 't' or '\\' or '\'' => 2, | ||
| '$' when position + 2 < end && text[position + 2] == '{' => 3, | ||
| 'u' => TryGetUnicodeEscapeSequenceLength(text, position, end), | ||
| _ => null, | ||
| }; | ||
| } | ||
|
|
||
| private static int? TryGetUnicodeEscapeSequenceLength(string text, int position, int end) | ||
| { | ||
| if (position + 3 >= end || text[position + 2] != '{') | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var hexDigitCount = 0; | ||
| for (var current = position + 3; current < end; current++) | ||
| { | ||
| if (text[current] == '}') | ||
| { | ||
| return hexDigitCount > 0 ? current - position + 1 : null; | ||
| } | ||
|
|
||
| if (!Uri.IsHexDigit(text[current])) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| hexDigitCount++; | ||
| } | ||
|
|
||
| return null; | ||
| } |
Member
There was a problem hiding this comment.
Isn't there code in the lexer we can reuse for this, instead of duplicating?
Contributor
Author
There was a problem hiding this comment.
Good question. The lexer validates escapes while producing string tokens and string values, but it does not retain sub-token source spans. Semantic highlighting needs those spans so it can leave gaps for the existing TextMate escape scopes, so there is not an existing lexer result to reuse here without adding a new lexer API just for highlighting.
Contributor
|
Test this change out locally with the following install scripts (Action run 28404602368) VSCode
Azure CLI
|
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.
Prevents semantic string tokens from covering escape sequences so TextMate escape scopes keep highlighting.
Fixes #18378
Microsoft Reviewers: Open in CodeFlow