Skip to content

Commit

Permalink
Merge pull request #287 from wise0704/comment
Browse files Browse the repository at this point in the history
Comment enhancements
  • Loading branch information
JoeRobich committed Aug 30, 2023
2 parents f4510f4 + 97ceea0 commit 5ba30a7
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 98 deletions.
111 changes: 75 additions & 36 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8899,58 +8899,72 @@
<array>
<dict>
<key>name</key>
<string>comment.block.cs</string>
<string>comment.block.documentation.cs</string>
<key>begin</key>
<string>/\*</string>
<key>beginCaptures</key>
<string>(^\s+)?(///)(?!/)</string>
<key>while</key>
<string>^(\s*)(///)(?!/)</string>
<key>captures</key>
<dict>
<key>0</key>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
<string>punctuation.whitespace.comment.leading.cs</string>
</dict>
</dict>
<key>end</key>
<string>\*/</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#xml-doc-comment</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>comment.block.documentation.cs</string>
<key>begin</key>
<string>(^\s+)?(?=//)</string>
<key>beginCaptures</key>
<string>(^\s+)?(/\*\*)(?!/)</string>
<key>end</key>
<string>(^\s+)?(\*/)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.whitespace.comment.leading.cs</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
</dict>
<key>end</key>
<string>(?=$)</string>
<key>patterns</key>
<array>
<dict>
<key>name</key>
<string>comment.block.documentation.cs</string>
<key>begin</key>
<string>(?&lt;!/)///(?!/)</string>
<key>beginCaptures</key>
<string>\G(?=(?~\*/)$)</string>
<key>while</key>
<string>^(\s*+)(\*(?!/))?(?=(?~\*/)$)</string>
<key>whileCaptures</key>
<dict>
<key>0</key>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.whitespace.comment.leading.cs</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
</dict>
<key>end</key>
<string>(?=$)</string>
<key>patterns</key>
<array>
<dict>
Expand All @@ -8960,23 +8974,48 @@
</array>
</dict>
<dict>
<key>name</key>
<string>comment.line.double-slash.cs</string>
<key>begin</key>
<string>(?&lt;!/)//(?:(?!/)|(?=//))</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
</dict>
<key>end</key>
<string>(?=$)</string>
<key>include</key>
<string>#xml-doc-comment</string>
</dict>
</array>
</dict>
<dict>
<key>name</key>
<string>comment.line.double-slash.cs</string>
<key>begin</key>
<string>(^\s+)?(//).*$</string>
<key>while</key>
<string>^(\s*)(//).*$</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.whitespace.comment.leading.cs</string>
</dict>
<key>2</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>xml-doc-comment</key>
Expand Down
65 changes: 43 additions & 22 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -5300,46 +5300,67 @@ repository:
comment:
patterns: [
{
name: "comment.block.cs"
begin: "/\\*"
beginCaptures:
"0":
name: "punctuation.definition.comment.cs"
end: "\\*/"
endCaptures:
"0":
name: "comment.block.documentation.cs"
begin: "(^\\s+)?(///)(?!/)"
while: "^(\\s*)(///)(?!/)"
captures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
"2":
name: "punctuation.definition.comment.cs"
patterns: [
{
include: "#xml-doc-comment"
}
]
}
{
begin: "(^\\s+)?(?=//)"
beginCaptures:
name: "comment.block.documentation.cs"
begin: "(^\\s+)?(/\\*\\*)(?!/)"
end: "(^\\s+)?(\\*/)"
captures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
end: "(?=$)"
"2":
name: "punctuation.definition.comment.cs"
patterns: [
{
name: "comment.block.documentation.cs"
begin: "(?<!/)///(?!/)"
beginCaptures:
"0":
begin: "\\G(?=(?~\\*/)$)"
while: "^(\\s*+)(\\*(?!/))?(?=(?~\\*/)$)"
whileCaptures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
"2":
name: "punctuation.definition.comment.cs"
end: "(?=$)"
patterns: [
{
include: "#xml-doc-comment"
}
]
}
{
name: "comment.line.double-slash.cs"
begin: "(?<!/)//(?:(?!/)|(?=//))"
beginCaptures:
"0":
name: "punctuation.definition.comment.cs"
end: "(?=$)"
include: "#xml-doc-comment"
}
]
}
{
name: "comment.line.double-slash.cs"
begin: "(^\\s+)?(//).*$"
while: "^(\\s*)(//).*$"
captures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
"2":
name: "punctuation.definition.comment.cs"
}
{
name: "comment.block.cs"
begin: "/\\*"
end: "\\*/"
captures:
"0":
name: "punctuation.definition.comment.cs"
}
]
"xml-doc-comment":
patterns: [
Expand Down
52 changes: 31 additions & 21 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3474,30 +3474,40 @@ repository:

comment:
patterns:
- name: comment.block.cs
begin: /\*
beginCaptures:
'0': { name: punctuation.definition.comment.cs }
end: \*/
endCaptures:
'0': { name: punctuation.definition.comment.cs }
- begin: (^\s+)?(?=//)
beginCaptures:
'1': { name: punctuation.whitespace.comment.leading.cs }
end: (?=$)
- name: comment.block.documentation.cs
begin: (^\s+)?(///)(?!/)
while: ^(\s*)(///)(?!/)
captures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
patterns:
- name: comment.block.documentation.cs
begin: (?<!/)///(?!/)
beginCaptures:
'0': { name: punctuation.definition.comment.cs }
end: (?=$)
- include: '#xml-doc-comment'
- name: comment.block.documentation.cs
begin: (^\s+)?(/\*\*)(?!/)
end: (^\s+)?(\*/)
captures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
patterns:
- begin: \G(?=(?~\*/)$)
while: ^(\s*+)(\*(?!/))?(?=(?~\*/)$)
whileCaptures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
patterns:
- include: '#xml-doc-comment'
- name: comment.line.double-slash.cs
begin: (?<!/)//(?:(?!/)|(?=//))
beginCaptures:
'0': { name: punctuation.definition.comment.cs }
end: (?=$)
- include: '#xml-doc-comment'
- name: comment.line.double-slash.cs
begin: (^\s+)?(//).*$
while: ^(\s*)(//).*$
captures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
- name: comment.block.cs
begin: /\*
end: \*/
captures:
0: { name: punctuation.definition.comment.cs }

xml-doc-comment:
patterns:
Expand Down
19 changes: 0 additions & 19 deletions test/preprocessor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,6 @@ describe("Preprocessor", () => {
]);
});

it("#if (Foo != true) && Bar //Foo", async () => {
const input = `#if (Foo != true) && Bar //Foo`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.Hash,
Token.Keyword.Preprocessor.If,
Token.Punctuation.OpenParen,
Token.Identifier.PreprocessorSymbol("Foo"),
Token.Operator.Relational.NotEqual,
Token.Literal.Boolean.True,
Token.Punctuation.CloseParen,
Token.Operator.Logical.And,
Token.Identifier.PreprocessorSymbol("Bar"),
Token.Comment.SingleLine.Start,
Token.Comment.SingleLine.Text("Foo")
]);
});

it("#elif true", async () => {
const input = `#elif true`;
const tokens = await tokenize(input);
Expand Down
3 changes: 3 additions & 0 deletions test/utils/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,10 @@ export namespace Token {
}

export const Begin = createToken('///', 'punctuation.definition.comment.cs');
export const BeginDelim = createToken('/**', 'punctuation.definition.comment.cs');
export const Colon = createToken(':', 'punctuation.separator.colon.cs');
export const Delim = createToken('*', 'punctuation.definition.comment.cs');
export const End = createToken('*/', 'punctuation.definition.comment.cs');
export const Equals = createToken('=', 'punctuation.separator.equals.cs');
export const Text = (text: string) => createToken(text, 'comment.block.documentation.cs');
}
Expand Down
Loading

0 comments on commit 5ba30a7

Please sign in to comment.