Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8574,7 +8574,7 @@
<array>
<dict>
<key>include</key>
<string>#comment</string>
<string>#preprocessor-comment</string>
</dict>
<dict>
<key>include</key>
Expand Down Expand Up @@ -8626,6 +8626,42 @@
</dict>
</array>
</dict>
<key>preprocessor-comment</key>
<dict>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>comment.line.double-slash.cs</string>
<key>match</key>
<string>(//).*(?=$)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
</dict>
</dict>
<dict>
<key>name</key>
<string>comment.block.cs</string>
<key>begin</key>
<string>/\*</string>
<key>end</key>
<string>\*/</string>
<key>captures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
</dict>
</dict>
</array>
</dict>
<key>preprocessor-define-or-undef</key>
<dict>
<key>match</key>
Expand Down Expand Up @@ -8672,7 +8708,7 @@
<array>
<dict>
<key>include</key>
<string>#comment</string>
<string>#preprocessor-comment</string>
</dict>
<dict>
<key>include</key>
Expand Down
22 changes: 20 additions & 2 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -5166,7 +5166,7 @@ repository:
end: "(?<=$)"
patterns: [
{
include: "#comment"
include: "#preprocessor-comment"
}
{
include: "#preprocessor-define-or-undef"
Expand Down Expand Up @@ -5205,6 +5205,24 @@ repository:
include: "#preprocessor-app-directive"
}
]
"preprocessor-comment":
patterns: [
{
name: "comment.line.double-slash.cs"
match: "(//).*(?=$)"
captures:
"1":
name: "punctuation.definition.comment.cs"
}
{
name: "comment.block.cs"
begin: "/\\*"
end: "\\*/"
captures:
"0":
name: "punctuation.definition.comment.cs"
}
]
"preprocessor-define-or-undef":
match: "\\b(?:(define)|(undef))\\b\\s*\\b([_[:alpha:]][_[:alnum:]]*)\\b"
captures:
Expand All @@ -5224,7 +5242,7 @@ repository:
end: "(?=$)"
patterns: [
{
include: "#comment"
include: "#preprocessor-comment"
}
{
include: "#preprocessor-expression"
Expand Down
16 changes: 14 additions & 2 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,7 @@ repository:
'1': { name: punctuation.separator.hash.cs }
end: (?<=$)
patterns:
- include: '#comment'
- include: '#preprocessor-comment'
- include: '#preprocessor-define-or-undef'
- include: '#preprocessor-if-or-elif'
- include: '#preprocessor-else-or-endif'
Expand All @@ -3390,6 +3390,18 @@ repository:
- include: '#preprocessor-pragma-checksum'
- include: '#preprocessor-app-directive'

preprocessor-comment:
patterns:
- name: comment.line.double-slash.cs
match: (//).*(?=$)
captures:
'1': { name: punctuation.definition.comment.cs }
- name: comment.block.cs
begin: /\*
end: \*/
captures:
0: { name: punctuation.definition.comment.cs }

preprocessor-define-or-undef:
match: \b(?:(define)|(undef))\b\s*\b([_[:alpha:]][_[:alnum:]]*)\b
captures:
Expand All @@ -3404,7 +3416,7 @@ repository:
'2': { name: keyword.preprocessor.elif.cs }
end: (?=$)
patterns:
- include: '#comment'
- include: '#preprocessor-comment'
- include: '#preprocessor-expression'

preprocessor-else-or-endif:
Expand Down
50 changes: 50 additions & 0 deletions test/preprocessor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,56 @@ public ActionResult Register()
Token.Literal.String(`"System.Net.dll"`)
]);
});

it("#pragma warning disable with comment followed by code (issue)", async () => {
const input = Input.InClass(`
void Bar()
{
#pragma warning disable 0000 // Internal compiler error
var x = Baz(1, 2, 3, out object error);
#pragma warning restore 0000 // Internal compiler error
}`);
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.PrimitiveType.Void,
Token.Identifier.MethodName("Bar"),
Token.Punctuation.OpenParen,
Token.Punctuation.CloseParen,
Token.Punctuation.OpenBrace,
Token.Punctuation.Hash,
Token.Keyword.Preprocessor.Pragma,
Token.Keyword.Preprocessor.Warning,
Token.Keyword.Preprocessor.Disable,
Token.Literal.Numeric.Decimal("0000"),
Token.Comment.SingleLine.Start,
Token.Comment.SingleLine.Text(" Internal compiler error"),
Token.Keyword.Definition.Var,
Token.Identifier.LocalName("x"),
Token.Operator.Assignment,
Token.Identifier.MethodName("Baz"),
Token.Punctuation.OpenParen,
Token.Literal.Numeric.Decimal("1"),
Token.Punctuation.Comma,
Token.Literal.Numeric.Decimal("2"),
Token.Punctuation.Comma,
Token.Literal.Numeric.Decimal("3"),
Token.Punctuation.Comma,
Token.Keyword.Modifier.Out,
Token.PrimitiveType.Object,
Token.Identifier.LocalName("error"),
Token.Punctuation.CloseParen,
Token.Punctuation.Semicolon,
Token.Punctuation.Hash,
Token.Keyword.Preprocessor.Pragma,
Token.Keyword.Preprocessor.Warning,
Token.Keyword.Preprocessor.Restore,
Token.Literal.Numeric.Decimal("0000"),
Token.Comment.SingleLine.Start,
Token.Comment.SingleLine.Text(" Internal compiler error"),
Token.Punctuation.CloseBrace
]);
});
});

describe("AppDirectives", () => {
Expand Down