Skip to content

Commit

Permalink
Better handling of doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wise0704 committed Aug 29, 2023
1 parent d9aad52 commit 84da134
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 79 deletions.
54 changes: 15 additions & 39 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8749,8 +8749,10 @@
<key>name</key>
<string>comment.block.documentation.cs</string>
<key>begin</key>
<string>(^\s+)?(///)(?!/)(.*)$</string>
<key>beginCaptures</key>
<string>(^\s*)(///)(?!/)</string>
<key>while</key>
<string>(^\s*)(///)(?!/)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
Expand All @@ -8762,41 +8764,23 @@
<key>name</key>
<string>punctuation.definition.comment.cs</string>
</dict>
<key>3</key>
</dict>
<key>patterns</key>
<array>
<dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#xml-doc-comment</string>
</dict>
</array>
<key>include</key>
<string>#xml-doc-comment</string>
</dict>
</dict>
<key>while</key>
<string>\A(?!x)x</string>
</array>
</dict>
<dict>
<key>name</key>
<string>comment.block.documentation.cs</string>
<key>begin</key>
<string>(^\s+)?(/\*\*)(?!/)</string>
<key>beginCaptures</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>
<string>(^\s*)(/\*\*)(?!/)</string>
<key>end</key>
<string>(^\s+)?(\*/)</string>
<key>endCaptures</key>
<string>(^\s*)(\*/)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
Expand All @@ -8813,7 +8797,7 @@
<array>
<dict>
<key>match</key>
<string>(^\s+)?(\*)(?!/)</string>
<string>(^\s*)(\*)(?!/)</string>
<key>captures</key>
<dict>
<key>1</key>
Expand Down Expand Up @@ -8860,17 +8844,9 @@
<string>comment.block.cs</string>
<key>begin</key>
<string>/\*</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>endCaptures</key>
<key>captures</key>
<dict>
<key>0</key>
<dict>
Expand Down
35 changes: 13 additions & 22 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -5210,37 +5210,31 @@ repository:
patterns: [
{
name: "comment.block.documentation.cs"
begin: "(^\\s+)?(///)(?!/)(.*)$"
beginCaptures:
begin: "(^\\s*)(///)(?!/)"
while: "(^\\s*)(///)(?!/)"
captures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
"2":
name: "punctuation.definition.comment.cs"
"3":
patterns: [
{
include: "#xml-doc-comment"
}
]
while: "\\A(?!x)x"
patterns: [
{
include: "#xml-doc-comment"
}
]
}
{
name: "comment.block.documentation.cs"
begin: "(^\\s+)?(/\\*\\*)(?!/)"
beginCaptures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
"2":
name: "punctuation.definition.comment.cs"
end: "(^\\s+)?(\\*/)"
endCaptures:
begin: "(^\\s*)(/\\*\\*)(?!/)"
end: "(^\\s*)(\\*/)"
captures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
"2":
name: "punctuation.definition.comment.cs"
patterns: [
{
match: "(^\\s+)?(\\*)(?!/)"
match: "(^\\s*)(\\*)(?!/)"
captures:
"1":
name: "punctuation.whitespace.comment.leading.cs"
Expand All @@ -5265,11 +5259,8 @@ repository:
{
name: "comment.block.cs"
begin: "/\\*"
beginCaptures:
"0":
name: "punctuation.definition.comment.cs"
end: "\\*/"
endCaptures:
captures:
"0":
name: "punctuation.definition.comment.cs"
}
Expand Down
28 changes: 10 additions & 18 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3421,27 +3421,21 @@ repository:
comment:
patterns:
- name: comment.block.documentation.cs
begin: (^\s+)?(///)(?!/)(.*)$
beginCaptures:
begin: (^\s*)(///)(?!/)
while: (^\s*)(///)(?!/)
captures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
3:
patterns:
- include: '#xml-doc-comment'
# while forces search to move onto the next line,
# so the last character in the line comment cannot be detected with a lookbehind
while: \A(?!x)x
patterns:
- include: '#xml-doc-comment'
- name: comment.block.documentation.cs
begin: (^\s+)?(/\*\*)(?!/)
beginCaptures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
end: (^\s+)?(\*/)
endCaptures:
begin: (^\s*)(/\*\*)(?!/)
end: (^\s*)(\*/)
captures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
patterns:
- match: (^\s+)?(\*)(?!/)
- match: (^\s*)(\*)(?!/)
captures:
1: { name: punctuation.whitespace.comment.leading.cs }
2: { name: punctuation.definition.comment.cs }
Expand All @@ -3456,10 +3450,8 @@ repository:
while: \A(?!x)x
- name: comment.block.cs
begin: /\*
beginCaptures:
0: { name: punctuation.definition.comment.cs }
end: \*/
endCaptures:
captures:
0: { name: punctuation.definition.comment.cs }

xml-doc-comment:
Expand Down
23 changes: 23 additions & 0 deletions test/xml-doc-comment.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ describe("XML Doc Comments", () => {
]);
});

it("start & end tag with content", async () => {
const input = `
/// <summary>
/// Text
/// </summary>`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.XmlDocComment.Begin,
Token.XmlDocComment.Text(" "),
Token.XmlDocComment.Tag.StartTagBegin,
Token.XmlDocComment.Tag.Name("summary"),
Token.XmlDocComment.Tag.StartTagEnd,
Token.XmlDocComment.Begin,
Token.XmlDocComment.Text(" Text"),
Token.XmlDocComment.Begin,
Token.XmlDocComment.Text(" "),
Token.XmlDocComment.Tag.EndTagBegin,
Token.XmlDocComment.Tag.Name("summary"),
Token.XmlDocComment.Tag.EndTagEnd
]);
});

it("empty tag", async () => {
const input = `/// <summary />`;
const tokens = await tokenize(input);
Expand Down

0 comments on commit 84da134

Please sign in to comment.