From 84da13430640539ba083bf638d20e0db8fbef351 Mon Sep 17 00:00:00 2001 From: Daniel Jeong Date: Tue, 29 Aug 2023 11:29:33 +0000 Subject: [PATCH] Better handling of doc comments --- grammars/csharp.tmLanguage | 54 +++++++++------------------------ grammars/csharp.tmLanguage.cson | 35 ++++++++------------- src/csharp.tmLanguage.yml | 28 ++++++----------- test/xml-doc-comment.tests.ts | 23 ++++++++++++++ 4 files changed, 61 insertions(+), 79 deletions(-) diff --git a/grammars/csharp.tmLanguage b/grammars/csharp.tmLanguage index 60f7324..0af38fd 100644 --- a/grammars/csharp.tmLanguage +++ b/grammars/csharp.tmLanguage @@ -8749,8 +8749,10 @@ name comment.block.documentation.cs begin - (^\s+)?(///)(?!/)(.*)$ - beginCaptures + (^\s*)(///)(?!/) + while + (^\s*)(///)(?!/) + captures 1 @@ -8762,41 +8764,23 @@ name punctuation.definition.comment.cs - 3 + + patterns + - patterns - - - include - #xml-doc-comment - - + include + #xml-doc-comment - - while - \A(?!x)x + name comment.block.documentation.cs begin - (^\s+)?(/\*\*)(?!/) - beginCaptures - - 1 - - name - punctuation.whitespace.comment.leading.cs - - 2 - - name - punctuation.definition.comment.cs - - + (^\s*)(/\*\*)(?!/) end - (^\s+)?(\*/) - endCaptures + (^\s*)(\*/) + captures 1 @@ -8813,7 +8797,7 @@ match - (^\s+)?(\*)(?!/) + (^\s*)(\*)(?!/) captures 1 @@ -8860,17 +8844,9 @@ comment.block.cs begin /\* - beginCaptures - - 0 - - name - punctuation.definition.comment.cs - - end \*/ - endCaptures + captures 0 diff --git a/grammars/csharp.tmLanguage.cson b/grammars/csharp.tmLanguage.cson index 89d9010..29ea8dc 100644 --- a/grammars/csharp.tmLanguage.cson +++ b/grammars/csharp.tmLanguage.cson @@ -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" @@ -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" } diff --git a/src/csharp.tmLanguage.yml b/src/csharp.tmLanguage.yml index 5a1ca9d..f46656c 100644 --- a/src/csharp.tmLanguage.yml +++ b/src/csharp.tmLanguage.yml @@ -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 } @@ -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: diff --git a/test/xml-doc-comment.tests.ts b/test/xml-doc-comment.tests.ts index 2435953..2b0e265 100644 --- a/test/xml-doc-comment.tests.ts +++ b/test/xml-doc-comment.tests.ts @@ -36,6 +36,29 @@ describe("XML Doc Comments", () => { ]); }); + it("start & end tag with content", async () => { + const input = ` +/// +/// Text +/// `; + 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 = `/// `; const tokens = await tokenize(input);