Skip to content

Commit 5ba30a7

Browse files
authored
Merge pull request #287 from wise0704/comment
Comment enhancements
2 parents f4510f4 + 97ceea0 commit 5ba30a7

File tree

6 files changed

+254
-98
lines changed

6 files changed

+254
-98
lines changed

grammars/csharp.tmLanguage

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8899,58 +8899,72 @@
88998899
<array>
89008900
<dict>
89018901
<key>name</key>
8902-
<string>comment.block.cs</string>
8902+
<string>comment.block.documentation.cs</string>
89038903
<key>begin</key>
8904-
<string>/\*</string>
8905-
<key>beginCaptures</key>
8904+
<string>(^\s+)?(///)(?!/)</string>
8905+
<key>while</key>
8906+
<string>^(\s*)(///)(?!/)</string>
8907+
<key>captures</key>
89068908
<dict>
8907-
<key>0</key>
8909+
<key>1</key>
89088910
<dict>
89098911
<key>name</key>
8910-
<string>punctuation.definition.comment.cs</string>
8912+
<string>punctuation.whitespace.comment.leading.cs</string>
89118913
</dict>
8912-
</dict>
8913-
<key>end</key>
8914-
<string>\*/</string>
8915-
<key>endCaptures</key>
8916-
<dict>
8917-
<key>0</key>
8914+
<key>2</key>
89188915
<dict>
89198916
<key>name</key>
89208917
<string>punctuation.definition.comment.cs</string>
89218918
</dict>
89228919
</dict>
8920+
<key>patterns</key>
8921+
<array>
8922+
<dict>
8923+
<key>include</key>
8924+
<string>#xml-doc-comment</string>
8925+
</dict>
8926+
</array>
89238927
</dict>
89248928
<dict>
8929+
<key>name</key>
8930+
<string>comment.block.documentation.cs</string>
89258931
<key>begin</key>
8926-
<string>(^\s+)?(?=//)</string>
8927-
<key>beginCaptures</key>
8932+
<string>(^\s+)?(/\*\*)(?!/)</string>
8933+
<key>end</key>
8934+
<string>(^\s+)?(\*/)</string>
8935+
<key>captures</key>
89288936
<dict>
89298937
<key>1</key>
89308938
<dict>
89318939
<key>name</key>
89328940
<string>punctuation.whitespace.comment.leading.cs</string>
89338941
</dict>
8942+
<key>2</key>
8943+
<dict>
8944+
<key>name</key>
8945+
<string>punctuation.definition.comment.cs</string>
8946+
</dict>
89348947
</dict>
8935-
<key>end</key>
8936-
<string>(?=$)</string>
89378948
<key>patterns</key>
89388949
<array>
89398950
<dict>
8940-
<key>name</key>
8941-
<string>comment.block.documentation.cs</string>
89428951
<key>begin</key>
8943-
<string>(?&lt;!/)///(?!/)</string>
8944-
<key>beginCaptures</key>
8952+
<string>\G(?=(?~\*/)$)</string>
8953+
<key>while</key>
8954+
<string>^(\s*+)(\*(?!/))?(?=(?~\*/)$)</string>
8955+
<key>whileCaptures</key>
89458956
<dict>
8946-
<key>0</key>
8957+
<key>1</key>
8958+
<dict>
8959+
<key>name</key>
8960+
<string>punctuation.whitespace.comment.leading.cs</string>
8961+
</dict>
8962+
<key>2</key>
89478963
<dict>
89488964
<key>name</key>
89498965
<string>punctuation.definition.comment.cs</string>
89508966
</dict>
89518967
</dict>
8952-
<key>end</key>
8953-
<string>(?=$)</string>
89548968
<key>patterns</key>
89558969
<array>
89568970
<dict>
@@ -8960,23 +8974,48 @@
89608974
</array>
89618975
</dict>
89628976
<dict>
8963-
<key>name</key>
8964-
<string>comment.line.double-slash.cs</string>
8965-
<key>begin</key>
8966-
<string>(?&lt;!/)//(?:(?!/)|(?=//))</string>
8967-
<key>beginCaptures</key>
8968-
<dict>
8969-
<key>0</key>
8970-
<dict>
8971-
<key>name</key>
8972-
<string>punctuation.definition.comment.cs</string>
8973-
</dict>
8974-
</dict>
8975-
<key>end</key>
8976-
<string>(?=$)</string>
8977+
<key>include</key>
8978+
<string>#xml-doc-comment</string>
89778979
</dict>
89788980
</array>
89798981
</dict>
8982+
<dict>
8983+
<key>name</key>
8984+
<string>comment.line.double-slash.cs</string>
8985+
<key>begin</key>
8986+
<string>(^\s+)?(//).*$</string>
8987+
<key>while</key>
8988+
<string>^(\s*)(//).*$</string>
8989+
<key>captures</key>
8990+
<dict>
8991+
<key>1</key>
8992+
<dict>
8993+
<key>name</key>
8994+
<string>punctuation.whitespace.comment.leading.cs</string>
8995+
</dict>
8996+
<key>2</key>
8997+
<dict>
8998+
<key>name</key>
8999+
<string>punctuation.definition.comment.cs</string>
9000+
</dict>
9001+
</dict>
9002+
</dict>
9003+
<dict>
9004+
<key>name</key>
9005+
<string>comment.block.cs</string>
9006+
<key>begin</key>
9007+
<string>/\*</string>
9008+
<key>end</key>
9009+
<string>\*/</string>
9010+
<key>captures</key>
9011+
<dict>
9012+
<key>0</key>
9013+
<dict>
9014+
<key>name</key>
9015+
<string>punctuation.definition.comment.cs</string>
9016+
</dict>
9017+
</dict>
9018+
</dict>
89809019
</array>
89819020
</dict>
89829021
<key>xml-doc-comment</key>

grammars/csharp.tmLanguage.cson

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5300,46 +5300,67 @@ repository:
53005300
comment:
53015301
patterns: [
53025302
{
5303-
name: "comment.block.cs"
5304-
begin: "/\\*"
5305-
beginCaptures:
5306-
"0":
5307-
name: "punctuation.definition.comment.cs"
5308-
end: "\\*/"
5309-
endCaptures:
5310-
"0":
5303+
name: "comment.block.documentation.cs"
5304+
begin: "(^\\s+)?(///)(?!/)"
5305+
while: "^(\\s*)(///)(?!/)"
5306+
captures:
5307+
"1":
5308+
name: "punctuation.whitespace.comment.leading.cs"
5309+
"2":
53115310
name: "punctuation.definition.comment.cs"
5311+
patterns: [
5312+
{
5313+
include: "#xml-doc-comment"
5314+
}
5315+
]
53125316
}
53135317
{
5314-
begin: "(^\\s+)?(?=//)"
5315-
beginCaptures:
5318+
name: "comment.block.documentation.cs"
5319+
begin: "(^\\s+)?(/\\*\\*)(?!/)"
5320+
end: "(^\\s+)?(\\*/)"
5321+
captures:
53165322
"1":
53175323
name: "punctuation.whitespace.comment.leading.cs"
5318-
end: "(?=$)"
5324+
"2":
5325+
name: "punctuation.definition.comment.cs"
53195326
patterns: [
53205327
{
5321-
name: "comment.block.documentation.cs"
5322-
begin: "(?<!/)///(?!/)"
5323-
beginCaptures:
5324-
"0":
5328+
begin: "\\G(?=(?~\\*/)$)"
5329+
while: "^(\\s*+)(\\*(?!/))?(?=(?~\\*/)$)"
5330+
whileCaptures:
5331+
"1":
5332+
name: "punctuation.whitespace.comment.leading.cs"
5333+
"2":
53255334
name: "punctuation.definition.comment.cs"
5326-
end: "(?=$)"
53275335
patterns: [
53285336
{
53295337
include: "#xml-doc-comment"
53305338
}
53315339
]
53325340
}
53335341
{
5334-
name: "comment.line.double-slash.cs"
5335-
begin: "(?<!/)//(?:(?!/)|(?=//))"
5336-
beginCaptures:
5337-
"0":
5338-
name: "punctuation.definition.comment.cs"
5339-
end: "(?=$)"
5342+
include: "#xml-doc-comment"
53405343
}
53415344
]
53425345
}
5346+
{
5347+
name: "comment.line.double-slash.cs"
5348+
begin: "(^\\s+)?(//).*$"
5349+
while: "^(\\s*)(//).*$"
5350+
captures:
5351+
"1":
5352+
name: "punctuation.whitespace.comment.leading.cs"
5353+
"2":
5354+
name: "punctuation.definition.comment.cs"
5355+
}
5356+
{
5357+
name: "comment.block.cs"
5358+
begin: "/\\*"
5359+
end: "\\*/"
5360+
captures:
5361+
"0":
5362+
name: "punctuation.definition.comment.cs"
5363+
}
53435364
]
53445365
"xml-doc-comment":
53455366
patterns: [

src/csharp.tmLanguage.yml

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,30 +3474,40 @@ repository:
34743474

34753475
comment:
34763476
patterns:
3477-
- name: comment.block.cs
3478-
begin: /\*
3479-
beginCaptures:
3480-
'0': { name: punctuation.definition.comment.cs }
3481-
end: \*/
3482-
endCaptures:
3483-
'0': { name: punctuation.definition.comment.cs }
3484-
- begin: (^\s+)?(?=//)
3485-
beginCaptures:
3486-
'1': { name: punctuation.whitespace.comment.leading.cs }
3487-
end: (?=$)
3477+
- name: comment.block.documentation.cs
3478+
begin: (^\s+)?(///)(?!/)
3479+
while: ^(\s*)(///)(?!/)
3480+
captures:
3481+
1: { name: punctuation.whitespace.comment.leading.cs }
3482+
2: { name: punctuation.definition.comment.cs }
34883483
patterns:
3489-
- name: comment.block.documentation.cs
3490-
begin: (?<!/)///(?!/)
3491-
beginCaptures:
3492-
'0': { name: punctuation.definition.comment.cs }
3493-
end: (?=$)
3484+
- include: '#xml-doc-comment'
3485+
- name: comment.block.documentation.cs
3486+
begin: (^\s+)?(/\*\*)(?!/)
3487+
end: (^\s+)?(\*/)
3488+
captures:
3489+
1: { name: punctuation.whitespace.comment.leading.cs }
3490+
2: { name: punctuation.definition.comment.cs }
3491+
patterns:
3492+
- begin: \G(?=(?~\*/)$)
3493+
while: ^(\s*+)(\*(?!/))?(?=(?~\*/)$)
3494+
whileCaptures:
3495+
1: { name: punctuation.whitespace.comment.leading.cs }
3496+
2: { name: punctuation.definition.comment.cs }
34943497
patterns:
34953498
- include: '#xml-doc-comment'
3496-
- name: comment.line.double-slash.cs
3497-
begin: (?<!/)//(?:(?!/)|(?=//))
3498-
beginCaptures:
3499-
'0': { name: punctuation.definition.comment.cs }
3500-
end: (?=$)
3499+
- include: '#xml-doc-comment'
3500+
- name: comment.line.double-slash.cs
3501+
begin: (^\s+)?(//).*$
3502+
while: ^(\s*)(//).*$
3503+
captures:
3504+
1: { name: punctuation.whitespace.comment.leading.cs }
3505+
2: { name: punctuation.definition.comment.cs }
3506+
- name: comment.block.cs
3507+
begin: /\*
3508+
end: \*/
3509+
captures:
3510+
0: { name: punctuation.definition.comment.cs }
35013511

35023512
xml-doc-comment:
35033513
patterns:

test/preprocessor.tests.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,25 +217,6 @@ describe("Preprocessor", () => {
217217
]);
218218
});
219219

220-
it("#if (Foo != true) && Bar //Foo", async () => {
221-
const input = `#if (Foo != true) && Bar //Foo`;
222-
const tokens = await tokenize(input);
223-
224-
tokens.should.deep.equal([
225-
Token.Punctuation.Hash,
226-
Token.Keyword.Preprocessor.If,
227-
Token.Punctuation.OpenParen,
228-
Token.Identifier.PreprocessorSymbol("Foo"),
229-
Token.Operator.Relational.NotEqual,
230-
Token.Literal.Boolean.True,
231-
Token.Punctuation.CloseParen,
232-
Token.Operator.Logical.And,
233-
Token.Identifier.PreprocessorSymbol("Bar"),
234-
Token.Comment.SingleLine.Start,
235-
Token.Comment.SingleLine.Text("Foo")
236-
]);
237-
});
238-
239220
it("#elif true", async () => {
240221
const input = `#elif true`;
241222
const tokens = await tokenize(input);

test/utils/tokenize.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,10 @@ export namespace Token {
660660
}
661661

662662
export const Begin = createToken('///', 'punctuation.definition.comment.cs');
663+
export const BeginDelim = createToken('/**', 'punctuation.definition.comment.cs');
663664
export const Colon = createToken(':', 'punctuation.separator.colon.cs');
665+
export const Delim = createToken('*', 'punctuation.definition.comment.cs');
666+
export const End = createToken('*/', 'punctuation.definition.comment.cs');
664667
export const Equals = createToken('=', 'punctuation.separator.equals.cs');
665668
export const Text = (text: string) => createToken(text, 'comment.block.documentation.cs');
666669
}

0 commit comments

Comments
 (0)