Skip to content

Commit 5b36228

Browse files
authored
Switch from using "while" to "end" and adjust nested rules accordingly (#75)
* Add additional tests for unclosed code blocks in comments * Switch from using "while" to "end" and adjust nested rules accordingly * Update date * Update date in changelog
1 parent d3bc5c4 commit 5b36228

File tree

5 files changed

+237
-49
lines changed

5 files changed

+237
-49
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.4.0 (2024-11-14)
2+
3+
- Removed use of 'while' in the grammar to avoid some differences in implementations between GitHub and VS Code
4+
- Improved handling of unclosed code blocks in dartdoc comments
5+
16
## 1.3.0 (2024-07-31)
27

38
- Added support for digit separators (`_`).

grammars/dart.json

+29-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dart",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"fileTypes": [
55
"dart"
66
],
@@ -69,6 +69,16 @@
6969
],
7070

7171
"repository": {
72+
"dartdoc-codeblock-triple": {
73+
"begin": "^\\s*///\\s*(?!\\s*```)",
74+
"end": "\n",
75+
"contentName": "variable.other.source.dart"
76+
},
77+
"dartdoc-codeblock-block": {
78+
"begin": "^\\s*\\*\\s*(?!(\\s*```|\/))",
79+
"end": "\n",
80+
"contentName": "variable.other.source.dart"
81+
},
7282
"dartdoc": {
7383
"patterns": [
7484
{
@@ -80,30 +90,31 @@
8090
}
8191
},
8292
{
83-
"match": "^ {4,}(?![ \\*]).*",
84-
"captures": {
85-
"0": {
86-
"name": "variable.name.source.dart"
93+
"begin": "^\\s*///\\s*(```)",
94+
"end": "^\\s*///\\s*(```)|^(?!\\s*///)",
95+
"patterns": [
96+
{
97+
"include": "#dartdoc-codeblock-triple"
8798
}
88-
}
99+
]
89100
},
90101
{
91-
"contentName": "variable.other.source.dart",
92-
"begin": "```.*?$",
93-
"end": "```"
102+
"begin": "^\\s*\\*\\s*(```)",
103+
"end": "^\\s*\\*\\s*(```)|^(?=\\s*\\*\/)",
104+
"patterns": [
105+
{
106+
"include": "#dartdoc-codeblock-block"
107+
}
108+
]
94109
},
95110
{
96-
"match": "(`[^`]+?`)",
97-
"captures": {
98-
"0": {
99-
"name": "variable.other.source.dart"
100-
}
101-
}
111+
"match": "`[^`\n]+`",
112+
"name": "variable.other.source.dart"
102113
},
103114
{
104-
"match": "(\\* (( ).*))$",
115+
"match": "\\s{4,}(.*)$",
105116
"captures": {
106-
"2": {
117+
"1": {
107118
"name": "variable.other.source.dart"
108119
}
109120
}
@@ -157,7 +168,7 @@
157168
{
158169
"name": "comment.block.documentation.dart",
159170
"begin": "///",
160-
"while": "^\\s*///",
171+
"end": "^(?!\\s*///)",
161172
"patterns": [
162173
{
163174
"include": "#dartdoc"

pubspec.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ environment:
44
sdk: ^3.2.0
55

66
dev_dependencies:
7-
collection: ^1.18.0
8-
dart_flutter_team_lints: ^2.1.1
7+
collection: ^1.19.0
8+
dart_flutter_team_lints: ^3.2.1
99
path: ^1.9.0
10-
string_scanner: ^1.2.0
11-
test: ^1.25.2
10+
string_scanner: ^1.4.0
11+
test: ^1.25.8

test/goldens/comments.dart.golden

+138-21
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,143 @@
55
>// found in the LICENSE file.
66
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.dart
77
>
8-
>/// Multiline dartdoc comment.
9-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
8+
>/// Multiline dartdoc comment with triple backticks.
9+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
1010
>///
1111
#^^^ comment.block.documentation.dart
1212
>/// ```
1313
#^^^^^^^ comment.block.documentation.dart
14-
>/// doc
14+
>/// code
15+
#^^^^ comment.block.documentation.dart
16+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
17+
>/// ```
18+
#^^^^^^^ comment.block.documentation.dart
19+
>///
20+
#^^^ comment.block.documentation.dart
21+
>/// ...
22+
#^^^^^^^ comment.block.documentation.dart
23+
>var doc1;
24+
#^^^ storage.type.primitive.dart
25+
# ^ punctuation.terminator.dart
26+
>
27+
>/// Multiline dartdoc comment with unclosed triple backticks.
28+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
29+
>///
1530
#^^^ comment.block.documentation.dart
16-
# ^^^^ comment.block.documentation.dart variable.other.source.dart
1731
>/// ```
32+
#^^^^^^^ comment.block.documentation.dart
33+
>/// code
34+
#^^^^ comment.block.documentation.dart
35+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
36+
>var doc2;
37+
#^^^ storage.type.primitive.dart
38+
# ^ punctuation.terminator.dart
39+
>
40+
>/// Multiline dartdoc comment with unclosed backticks.
41+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
42+
>///
1843
#^^^ comment.block.documentation.dart
19-
# ^ comment.block.documentation.dart variable.other.source.dart
20-
# ^^^ comment.block.documentation.dart
44+
>/// `code
45+
#^^^^^^^^^ comment.block.documentation.dart
46+
>var doc3;
47+
#^^^ storage.type.primitive.dart
48+
# ^ punctuation.terminator.dart
49+
>
50+
>/// Multiline dartdoc comment with indented code.
51+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
52+
>///
53+
#^^^ comment.block.documentation.dart
54+
>/// code1
55+
#^^^^^^^^ comment.block.documentation.dart
56+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
57+
>/// code2
58+
#^^^^^^^^ comment.block.documentation.dart
59+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
60+
>///
61+
#^^^ comment.block.documentation.dart
62+
>/// code3
63+
#^^^^^^^^ comment.block.documentation.dart
64+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
2165
>///
2266
#^^^ comment.block.documentation.dart
2367
>/// ...
2468
#^^^^^^^ comment.block.documentation.dart
25-
>var a;
69+
>var doc4;
2670
#^^^ storage.type.primitive.dart
27-
# ^ punctuation.terminator.dart
71+
# ^ punctuation.terminator.dart
72+
>
73+
>/** Block dartdoc comment with triple backticks.
74+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
75+
> *
76+
#^^ comment.block.documentation.dart
77+
> * ```
78+
#^^^^^^ comment.block.documentation.dart
79+
> * code
80+
#^^^ comment.block.documentation.dart
81+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
82+
> * ```
83+
#^^^^^^ comment.block.documentation.dart
84+
> *
85+
#^^ comment.block.documentation.dart
86+
> * ...
87+
#^^^^^^ comment.block.documentation.dart
88+
> */
89+
#^^^ comment.block.documentation.dart
90+
>var blockDoc1;
91+
#^^^ storage.type.primitive.dart
92+
# ^ punctuation.terminator.dart
93+
>
94+
>/** Block dartdoc comment with unclosed triple backticks.
95+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
96+
> *
97+
#^^ comment.block.documentation.dart
98+
> * ```
99+
#^^^^^^ comment.block.documentation.dart
100+
> * code
101+
#^^^ comment.block.documentation.dart
102+
# ^^^^ comment.block.documentation.dart variable.other.source.dart
103+
> */
104+
#^^^ comment.block.documentation.dart
105+
>var blockDoc2;
106+
#^^^ storage.type.primitive.dart
107+
# ^ punctuation.terminator.dart
108+
>
109+
>/** Block dartdoc comment with unclosed backticks.
110+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
111+
> *
112+
#^^ comment.block.documentation.dart
113+
> * `code
114+
#^^^^^^^^ comment.block.documentation.dart
115+
> */
116+
#^^^ comment.block.documentation.dart
117+
>var blockDoc3;
118+
#^^^ storage.type.primitive.dart
119+
# ^ punctuation.terminator.dart
120+
>
121+
>/** Block dartdoc comment with indented code.
122+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
123+
> *
124+
#^^ comment.block.documentation.dart
125+
> * code1
126+
#^^^^^^^ comment.block.documentation.dart
127+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
128+
> * code2
129+
#^^^^^^^ comment.block.documentation.dart
130+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
131+
> *
132+
#^^ comment.block.documentation.dart
133+
> * code3
134+
#^^^^^^^ comment.block.documentation.dart
135+
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
136+
> *
137+
#^^ comment.block.documentation.dart
138+
> * ...
139+
#^^^^^^ comment.block.documentation.dart
140+
> */
141+
#^^^ comment.block.documentation.dart
142+
>var blockDoc4;
143+
#^^^ storage.type.primitive.dart
144+
# ^ punctuation.terminator.dart
28145
>
29146
>/// ``
30147
#^^^^^^ comment.block.documentation.dart
@@ -123,24 +240,24 @@
123240
#^^^ storage.type.primitive.dart
124241
# ^ punctuation.terminator.dart
125242
>
126-
>class A<dynamic /* comment */ > {
243+
>class A<T /* comment */ > {
127244
#^^^^^ keyword.declaration.dart
128245
# ^ support.class.dart
129246
# ^ other.source.dart
130-
# ^^^^^^^ support.class.dart
131-
# ^^^^^^^^^^^^^ comment.block.dart
132-
# ^ other.source.dart
133-
> void b<dynamic /* comment */ >() {}
247+
# ^ support.class.dart
248+
# ^^^^^^^^^^^^^ comment.block.dart
249+
# ^ other.source.dart
250+
> void b<T /* comment */ >() {}
134251
# ^^^^ storage.type.primitive.dart
135252
# ^ keyword.operator.comparison.dart
136-
# ^^^^^^^ support.class.dart
137-
# ^^^^^^^^^^^^^ comment.block.dart
138-
# ^ keyword.operator.comparison.dart
139-
> Future<dynamic /* comment */ > c() {}
253+
# ^ support.class.dart
254+
# ^^^^^^^^^^^^^ comment.block.dart
255+
# ^ keyword.operator.comparison.dart
256+
> Future<T /* comment */ > c() {}
140257
# ^^^^^^ support.class.dart
141258
# ^ other.source.dart
142-
# ^^^^^^^ support.class.dart
143-
# ^^^^^^^^^^^^^ comment.block.dart
144-
# ^ other.source.dart
145-
# ^ entity.name.function.dart
259+
# ^ support.class.dart
260+
# ^^^^^^^^^^^^^ comment.block.dart
261+
# ^ other.source.dart
262+
# ^ entity.name.function.dart
146263
>}

test/test_files/comments.dart

+61-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,69 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
/// Multiline dartdoc comment.
5+
/// Multiline dartdoc comment with triple backticks.
66
///
77
/// ```
8-
/// doc
8+
/// code
99
/// ```
1010
///
1111
/// ...
12-
var a;
12+
var doc1;
13+
14+
/// Multiline dartdoc comment with unclosed triple backticks.
15+
///
16+
/// ```
17+
/// code
18+
var doc2;
19+
20+
/// Multiline dartdoc comment with unclosed backticks.
21+
///
22+
/// `code
23+
var doc3;
24+
25+
/// Multiline dartdoc comment with indented code.
26+
///
27+
/// code1
28+
/// code2
29+
///
30+
/// code3
31+
///
32+
/// ...
33+
var doc4;
34+
35+
/** Block dartdoc comment with triple backticks.
36+
*
37+
* ```
38+
* code
39+
* ```
40+
*
41+
* ...
42+
*/
43+
var blockDoc1;
44+
45+
/** Block dartdoc comment with unclosed triple backticks.
46+
*
47+
* ```
48+
* code
49+
*/
50+
var blockDoc2;
51+
52+
/** Block dartdoc comment with unclosed backticks.
53+
*
54+
* `code
55+
*/
56+
var blockDoc3;
57+
58+
/** Block dartdoc comment with indented code.
59+
*
60+
* code1
61+
* code2
62+
*
63+
* code3
64+
*
65+
* ...
66+
*/
67+
var blockDoc4;
1368

1469
/// ``
1570
var noInlineCode;
@@ -56,7 +111,7 @@ var g;
56111
/// And a link to [example.org](http://example.org/).
57112
var h;
58113

59-
class A<dynamic /* comment */ > {
60-
void b<dynamic /* comment */ >() {}
61-
Future<dynamic /* comment */ > c() {}
114+
class A<T /* comment */ > {
115+
void b<T /* comment */ >() {}
116+
Future<T /* comment */ > c() {}
62117
}

0 commit comments

Comments
 (0)