Skip to content

Commit dcae1fb

Browse files
authored
Merge pull request #4902 from TechnologicalPizza/highlight-regex
Improved Regex syntax highlighting
2 parents 7095cda + 5d2400c commit dcae1fb

File tree

2 files changed

+90
-8
lines changed

2 files changed

+90
-8
lines changed

package.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,6 +3759,38 @@
37593759
{
37603760
"id": "xmlDocCommentText",
37613761
"description": ""
3762+
},
3763+
{
3764+
"id": "regexComment",
3765+
"description": ""
3766+
},
3767+
{
3768+
"id": "regexCharacterClass",
3769+
"description": ""
3770+
},
3771+
{
3772+
"id": "regexAnchor",
3773+
"description": ""
3774+
},
3775+
{
3776+
"id": "regexQuantifier",
3777+
"description": ""
3778+
},
3779+
{
3780+
"id": "regexGrouping",
3781+
"description": ""
3782+
},
3783+
{
3784+
"id": "regexAlternation",
3785+
"description": ""
3786+
},
3787+
{
3788+
"id": "regexSelfEscapedCharacter",
3789+
"description": ""
3790+
},
3791+
{
3792+
"id": "regexOtherEscape",
3793+
"description": ""
37623794
}
37633795
],
37643796
"semanticTokenModifiers": [],
@@ -3896,6 +3928,40 @@
38963928
],
38973929
"xmlDocCommentText": [
38983930
"comment.documentation.cs"
3931+
],
3932+
"regexComment": [
3933+
"string.regexp.comment.cs"
3934+
],
3935+
"regexCharacterClass": [
3936+
"constant.character.character-class.regexp.cs",
3937+
"constant.other.character-class.set.regexp.cs",
3938+
"constant.other.character-class.regexp.cs",
3939+
"constant.character.set.regexp.cs"
3940+
],
3941+
"regexAnchor": [
3942+
"keyword.control.anchor.regexp.cs"
3943+
],
3944+
"regexQuantifier": [
3945+
"keyword.operator.quantifier.regexp.cs"
3946+
],
3947+
"regexGrouping": [
3948+
"punctuation.definition.group.regexp.cs",
3949+
"punctuation.definition.group.assertion.regexp.cs",
3950+
"punctuation.definition.character-class.regexp.cs",
3951+
"punctuation.character.set.begin.regexp.cs",
3952+
"punctuation.character.set.end.regexp.cs",
3953+
"keyword.operator.negation.regexp.cs",
3954+
"support.other.parenthesis.regexp.cs"
3955+
],
3956+
"regexAlternation": [
3957+
"keyword.operator.or.regexp.cs",
3958+
"keyword.control.anchor.regexp.cs"
3959+
],
3960+
"regexSelfEscapedCharacter": [
3961+
"string.regexp.self-escaped-character.cs"
3962+
],
3963+
"regexOtherEscape": [
3964+
"string.regexp.other-escape.cs"
38993965
]
39003966
}
39013967
}

src/features/semanticTokensProvider.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ enum CustomTokenType {
6464
xmlDocCommentName,
6565
xmlDocCommentProcessingInstruction,
6666
xmlDocCommentText,
67+
regexComment,
68+
regexCharacterClass,
69+
regexAnchor,
70+
regexQuantifier,
71+
regexGrouping,
72+
regexAlternation,
73+
regexSelfEscapedCharacter,
74+
regexOtherEscape,
6775
}
6876

6977
// The default TokenModifiers defined by VS Code https://github.com/microsoft/vscode/blob/master/src/vs/platform/theme/common/tokenClassificationRegistry.ts#L393
@@ -281,6 +289,14 @@ tokenTypes[CustomTokenType.xmlDocCommentEntityReference] = "xmlDocCommentEntityR
281289
tokenTypes[CustomTokenType.xmlDocCommentName] = "xmlDocCommentName";
282290
tokenTypes[CustomTokenType.xmlDocCommentProcessingInstruction] = "xmlDocCommentProcessingInstruction";
283291
tokenTypes[CustomTokenType.xmlDocCommentText] = "xmlDocCommentText";
292+
tokenTypes[CustomTokenType.regexComment] = "regexComment";
293+
tokenTypes[CustomTokenType.regexCharacterClass] = "regexCharacterClass";
294+
tokenTypes[CustomTokenType.regexAnchor] = "regexAnchor";
295+
tokenTypes[CustomTokenType.regexQuantifier] = "regexQuantifier";
296+
tokenTypes[CustomTokenType.regexGrouping] = "regexGrouping";
297+
tokenTypes[CustomTokenType.regexAlternation] = "regexAlternation";
298+
tokenTypes[CustomTokenType.regexSelfEscapedCharacter] = "regexSelfEscapedCharacter";
299+
tokenTypes[CustomTokenType.regexOtherEscape] = "regexOtherEscape";
284300

285301
const tokenModifiers: string[] = [];
286302
tokenModifiers[DefaultTokenModifier.declaration] = 'declaration';
@@ -348,15 +364,15 @@ tokenTypeMap[SemanticHighlightClassification.XmlLiteralEntityReference] = undefi
348364
tokenTypeMap[SemanticHighlightClassification.XmlLiteralName] = undefined;
349365
tokenTypeMap[SemanticHighlightClassification.XmlLiteralProcessingInstruction] = undefined;
350366
tokenTypeMap[SemanticHighlightClassification.XmlLiteralText] = undefined;
351-
tokenTypeMap[SemanticHighlightClassification.RegexComment] = DefaultTokenType.regexp;
352-
tokenTypeMap[SemanticHighlightClassification.RegexCharacterClass] = DefaultTokenType.regexp;
353-
tokenTypeMap[SemanticHighlightClassification.RegexAnchor] = DefaultTokenType.regexp;
354-
tokenTypeMap[SemanticHighlightClassification.RegexQuantifier] = DefaultTokenType.regexp;
355-
tokenTypeMap[SemanticHighlightClassification.RegexGrouping] = DefaultTokenType.regexp;
356-
tokenTypeMap[SemanticHighlightClassification.RegexAlternation] = DefaultTokenType.regexp;
367+
tokenTypeMap[SemanticHighlightClassification.RegexComment] = CustomTokenType.regexComment;
368+
tokenTypeMap[SemanticHighlightClassification.RegexCharacterClass] = CustomTokenType.regexCharacterClass;
369+
tokenTypeMap[SemanticHighlightClassification.RegexAnchor] = CustomTokenType.regexAnchor;
370+
tokenTypeMap[SemanticHighlightClassification.RegexQuantifier] = CustomTokenType.regexQuantifier;
371+
tokenTypeMap[SemanticHighlightClassification.RegexGrouping] = CustomTokenType.regexGrouping;
372+
tokenTypeMap[SemanticHighlightClassification.RegexAlternation] = CustomTokenType.regexAlternation;
357373
tokenTypeMap[SemanticHighlightClassification.RegexText] = DefaultTokenType.regexp;
358-
tokenTypeMap[SemanticHighlightClassification.RegexSelfEscapedCharacter] = DefaultTokenType.regexp;
359-
tokenTypeMap[SemanticHighlightClassification.RegexOtherEscape] = DefaultTokenType.regexp;
374+
tokenTypeMap[SemanticHighlightClassification.RegexSelfEscapedCharacter] = CustomTokenType.regexSelfEscapedCharacter;
375+
tokenTypeMap[SemanticHighlightClassification.RegexOtherEscape] = CustomTokenType.regexOtherEscape;
360376

361377
const tokenModifierMap: number[] = [];
362378
tokenModifierMap[SemanticHighlightModifier.Static] = 2 ** DefaultTokenModifier.static;

0 commit comments

Comments
 (0)