diff --git a/syntaxes/csharp.tmLanguage.yml b/syntaxes/csharp.tmLanguage.yml index 2665213a9..7406461a2 100644 --- a/syntaxes/csharp.tmLanguage.yml +++ b/syntaxes/csharp.tmLanguage.yml @@ -116,9 +116,11 @@ repository: expression: patterns: - include: '#checked-unchecked-expression' + - include: '#typeof-expression' - include: '#interpolated-string' - include: '#verbatim-interpolated-string' - include: '#literal' + - include: '#this-or-base-expression' - include: '#expression-operators' - include: '#cast-expression' - include: '#object-creation-expression' @@ -1174,6 +1176,17 @@ repository: patterns: - include: '#expression' + typeof-expression: + begin: (? { + + const input = Input.InMethod( +`configContent = rgx.Replace(configContent, $"name{suffix}\\""); +File.WriteAllText(_testConfigFile, configContent);`); + const tokens = tokenize(input); + + tokens.should.deep.equal([ + Token.Variables.ReadWrite("configContent"), + Token.Operators.Assignment, + Token.Variables.Object('rgx'), + Token.Punctuation.Accessor, + Token.Identifiers.MethodName("Replace"), + Token.Punctuation.OpenParen, + Token.Variables.ReadWrite("configContent"), + Token.Punctuation.Comma, + Token.Punctuation.InterpolatedString.Begin, + Token.Literals.String("name"), + Token.Punctuation.Interpolation.Begin, + Token.Variables.ReadWrite("suffix"), + Token.Punctuation.Interpolation.End, + Token.Literals.CharacterEscape("\\\""), + Token.Punctuation.String.End, + Token.Punctuation.CloseParen, + Token.Punctuation.Semicolon, + Token.Variables.Object("File"), + Token.Punctuation.Accessor, + Token.Identifiers.MethodName("WriteAllText"), + Token.Punctuation.OpenParen, + Token.Variables.ReadWrite("_testConfigFile"), + Token.Punctuation.Comma, + Token.Variables.ReadWrite("configContent"), + Token.Punctuation.CloseParen, + Token.Punctuation.Semicolon + ]); + }); + + it("highlight escaped double-quote properly (issue #1078 - repro 2)", () => { + + const input = Input.InMethod( +`throw new InvalidCastException( + $"The value \\"{this.Value} is of the type \\"{this.Type}\\". You asked for \\"{typeof(T)}\\".");`); + const tokens = tokenize(input); + + tokens.should.deep.equal([ + Token.Keywords.Throw, + Token.Keywords.New, + Token.Type("InvalidCastException"), + Token.Punctuation.OpenParen, + Token.Punctuation.InterpolatedString.Begin, + Token.Literals.String("The value "), + Token.Literals.CharacterEscape("\\\""), + Token.Punctuation.Interpolation.Begin, + Token.Keywords.This, + Token.Punctuation.Accessor, + Token.Variables.Property("Value"), + Token.Punctuation.Interpolation.End, + Token.Literals.String(" is of the type "), + Token.Literals.CharacterEscape("\\\""), + Token.Punctuation.Interpolation.Begin, + Token.Keywords.This, + Token.Punctuation.Accessor, + Token.Variables.Property("Type"), + Token.Punctuation.Interpolation.End, + Token.Literals.CharacterEscape("\\\""), + Token.Literals.String(". You asked for "), + Token.Literals.CharacterEscape("\\\""), + Token.Punctuation.Interpolation.Begin, + Token.Keywords.TypeOf, + Token.Punctuation.OpenParen, + Token.Type("T"), + Token.Punctuation.CloseParen, + Token.Punctuation.Interpolation.End, + Token.Literals.CharacterEscape("\\\""), + Token.Literals.String("."), + Token.Punctuation.InterpolatedString.End, + Token.Punctuation.CloseParen, + Token.Punctuation.Semicolon + ]); + }); }); }); \ No newline at end of file diff --git a/test/syntaxes/utils/tokenize.ts b/test/syntaxes/utils/tokenize.ts index 38ac91a73..f76704e4a 100644 --- a/test/syntaxes/utils/tokenize.ts +++ b/test/syntaxes/utils/tokenize.ts @@ -220,6 +220,7 @@ export namespace Token { export const This = createToken('this', 'keyword.other.this.cs'); export const Throw = createToken('throw', 'keyword.control.flow.throw.cs'); export const Try = createToken('try', 'keyword.control.try.cs'); + export const TypeOf = createToken('typeof', 'keyword.other.typeof.cs'); export const Unchecked = createToken('unchecked', 'keyword.other.unchecked.cs'); export const Using = createToken('using', 'keyword.other.using.cs'); export const When = createToken('when', 'keyword.control.try.when.cs');