Skip to content

Commit

Permalink
Switch from using "while" to "end" and adjust nested rules accordingly (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
DanTup authored Nov 18, 2024
1 parent d3bc5c4 commit 5b36228
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.4.0 (2024-11-14)

- Removed use of 'while' in the grammar to avoid some differences in implementations between GitHub and VS Code
- Improved handling of unclosed code blocks in dartdoc comments

## 1.3.0 (2024-07-31)

- Added support for digit separators (`_`).
Expand Down
47 changes: 29 additions & 18 deletions grammars/dart.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dart",
"version": "1.3.0",
"version": "1.4.0",
"fileTypes": [
"dart"
],
Expand Down Expand Up @@ -69,6 +69,16 @@
],

"repository": {
"dartdoc-codeblock-triple": {
"begin": "^\\s*///\\s*(?!\\s*```)",
"end": "\n",
"contentName": "variable.other.source.dart"
},
"dartdoc-codeblock-block": {
"begin": "^\\s*\\*\\s*(?!(\\s*```|\/))",
"end": "\n",
"contentName": "variable.other.source.dart"
},
"dartdoc": {
"patterns": [
{
Expand All @@ -80,30 +90,31 @@
}
},
{
"match": "^ {4,}(?![ \\*]).*",
"captures": {
"0": {
"name": "variable.name.source.dart"
"begin": "^\\s*///\\s*(```)",
"end": "^\\s*///\\s*(```)|^(?!\\s*///)",
"patterns": [
{
"include": "#dartdoc-codeblock-triple"
}
}
]
},
{
"contentName": "variable.other.source.dart",
"begin": "```.*?$",
"end": "```"
"begin": "^\\s*\\*\\s*(```)",
"end": "^\\s*\\*\\s*(```)|^(?=\\s*\\*\/)",
"patterns": [
{
"include": "#dartdoc-codeblock-block"
}
]
},
{
"match": "(`[^`]+?`)",
"captures": {
"0": {
"name": "variable.other.source.dart"
}
}
"match": "`[^`\n]+`",
"name": "variable.other.source.dart"
},
{
"match": "(\\* (( ).*))$",
"match": "\\s{4,}(.*)$",
"captures": {
"2": {
"1": {
"name": "variable.other.source.dart"
}
}
Expand Down Expand Up @@ -157,7 +168,7 @@
{
"name": "comment.block.documentation.dart",
"begin": "///",
"while": "^\\s*///",
"end": "^(?!\\s*///)",
"patterns": [
{
"include": "#dartdoc"
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ environment:
sdk: ^3.2.0

dev_dependencies:
collection: ^1.18.0
dart_flutter_team_lints: ^2.1.1
collection: ^1.19.0
dart_flutter_team_lints: ^3.2.1
path: ^1.9.0
string_scanner: ^1.2.0
test: ^1.25.2
string_scanner: ^1.4.0
test: ^1.25.8
159 changes: 138 additions & 21 deletions test/goldens/comments.dart.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,143 @@
>// found in the LICENSE file.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.double-slash.dart
>
>/// Multiline dartdoc comment.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
>/// Multiline dartdoc comment with triple backticks.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
>///
#^^^ comment.block.documentation.dart
>/// ```
#^^^^^^^ comment.block.documentation.dart
>/// doc
>/// code
#^^^^ comment.block.documentation.dart
# ^^^^ comment.block.documentation.dart variable.other.source.dart
>/// ```
#^^^^^^^ comment.block.documentation.dart
>///
#^^^ comment.block.documentation.dart
>/// ...
#^^^^^^^ comment.block.documentation.dart
>var doc1;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/// Multiline dartdoc comment with unclosed triple backticks.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
>///
#^^^ comment.block.documentation.dart
# ^^^^ comment.block.documentation.dart variable.other.source.dart
>/// ```
#^^^^^^^ comment.block.documentation.dart
>/// code
#^^^^ comment.block.documentation.dart
# ^^^^ comment.block.documentation.dart variable.other.source.dart
>var doc2;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/// Multiline dartdoc comment with unclosed backticks.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
>///
#^^^ comment.block.documentation.dart
# ^ comment.block.documentation.dart variable.other.source.dart
# ^^^ comment.block.documentation.dart
>/// `code
#^^^^^^^^^ comment.block.documentation.dart
>var doc3;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/// Multiline dartdoc comment with indented code.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
>///
#^^^ comment.block.documentation.dart
>/// code1
#^^^^^^^^ comment.block.documentation.dart
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
>/// code2
#^^^^^^^^ comment.block.documentation.dart
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
>///
#^^^ comment.block.documentation.dart
>/// code3
#^^^^^^^^ comment.block.documentation.dart
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
>///
#^^^ comment.block.documentation.dart
>/// ...
#^^^^^^^ comment.block.documentation.dart
>var a;
>var doc4;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
# ^ punctuation.terminator.dart
>
>/** Block dartdoc comment with triple backticks.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
> *
#^^ comment.block.documentation.dart
> * ```
#^^^^^^ comment.block.documentation.dart
> * code
#^^^ comment.block.documentation.dart
# ^^^^ comment.block.documentation.dart variable.other.source.dart
> * ```
#^^^^^^ comment.block.documentation.dart
> *
#^^ comment.block.documentation.dart
> * ...
#^^^^^^ comment.block.documentation.dart
> */
#^^^ comment.block.documentation.dart
>var blockDoc1;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/** Block dartdoc comment with unclosed triple backticks.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
> *
#^^ comment.block.documentation.dart
> * ```
#^^^^^^ comment.block.documentation.dart
> * code
#^^^ comment.block.documentation.dart
# ^^^^ comment.block.documentation.dart variable.other.source.dart
> */
#^^^ comment.block.documentation.dart
>var blockDoc2;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/** Block dartdoc comment with unclosed backticks.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
> *
#^^ comment.block.documentation.dart
> * `code
#^^^^^^^^ comment.block.documentation.dart
> */
#^^^ comment.block.documentation.dart
>var blockDoc3;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/** Block dartdoc comment with indented code.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.documentation.dart
> *
#^^ comment.block.documentation.dart
> * code1
#^^^^^^^ comment.block.documentation.dart
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
> * code2
#^^^^^^^ comment.block.documentation.dart
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
> *
#^^ comment.block.documentation.dart
> * code3
#^^^^^^^ comment.block.documentation.dart
# ^^^^^ comment.block.documentation.dart variable.other.source.dart
> *
#^^ comment.block.documentation.dart
> * ...
#^^^^^^ comment.block.documentation.dart
> */
#^^^ comment.block.documentation.dart
>var blockDoc4;
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>/// ``
#^^^^^^ comment.block.documentation.dart
Expand Down Expand Up @@ -123,24 +240,24 @@
#^^^ storage.type.primitive.dart
# ^ punctuation.terminator.dart
>
>class A<dynamic /* comment */ > {
>class A<T /* comment */ > {
#^^^^^ keyword.declaration.dart
# ^ support.class.dart
# ^ other.source.dart
# ^^^^^^^ support.class.dart
# ^^^^^^^^^^^^^ comment.block.dart
# ^ other.source.dart
> void b<dynamic /* comment */ >() {}
# ^ support.class.dart
# ^^^^^^^^^^^^^ comment.block.dart
# ^ other.source.dart
> void b<T /* comment */ >() {}
# ^^^^ storage.type.primitive.dart
# ^ keyword.operator.comparison.dart
# ^^^^^^^ support.class.dart
# ^^^^^^^^^^^^^ comment.block.dart
# ^ keyword.operator.comparison.dart
> Future<dynamic /* comment */ > c() {}
# ^ support.class.dart
# ^^^^^^^^^^^^^ comment.block.dart
# ^ keyword.operator.comparison.dart
> Future<T /* comment */ > c() {}
# ^^^^^^ support.class.dart
# ^ other.source.dart
# ^^^^^^^ support.class.dart
# ^^^^^^^^^^^^^ comment.block.dart
# ^ other.source.dart
# ^ entity.name.function.dart
# ^ support.class.dart
# ^^^^^^^^^^^^^ comment.block.dart
# ^ other.source.dart
# ^ entity.name.function.dart
>}
67 changes: 61 additions & 6 deletions test/test_files/comments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,69 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Multiline dartdoc comment.
/// Multiline dartdoc comment with triple backticks.
///
/// ```
/// doc
/// code
/// ```
///
/// ...
var a;
var doc1;

/// Multiline dartdoc comment with unclosed triple backticks.
///
/// ```
/// code
var doc2;

/// Multiline dartdoc comment with unclosed backticks.
///
/// `code
var doc3;

/// Multiline dartdoc comment with indented code.
///
/// code1
/// code2
///
/// code3
///
/// ...
var doc4;

/** Block dartdoc comment with triple backticks.
*
* ```
* code
* ```
*
* ...
*/
var blockDoc1;

/** Block dartdoc comment with unclosed triple backticks.
*
* ```
* code
*/
var blockDoc2;

/** Block dartdoc comment with unclosed backticks.
*
* `code
*/
var blockDoc3;

/** Block dartdoc comment with indented code.
*
* code1
* code2
*
* code3
*
* ...
*/
var blockDoc4;

/// ``
var noInlineCode;
Expand Down Expand Up @@ -56,7 +111,7 @@ var g;
/// And a link to [example.org](http://example.org/).
var h;

class A<dynamic /* comment */ > {
void b<dynamic /* comment */ >() {}
Future<dynamic /* comment */ > c() {}
class A<T /* comment */ > {
void b<T /* comment */ >() {}
Future<T /* comment */ > c() {}
}

0 comments on commit 5b36228

Please sign in to comment.