@@ -362,6 +362,12 @@ CoverageInfo _process(
362362 commentOn.commentOnToken.lexeme == "?." ) {
363363 // A comment on the actual call isn't pretty.
364364 // Allow the "bigger one".
365+ } else if (prevAdded.beginToken.charOffset ==
366+ commentOn.beginToken.charOffset &&
367+ prevAdded.endToken.charEnd == commentOn.endToken.charEnd &&
368+ prevAdded.allowToWrapInBlock) {
369+ // They have the same size and the previous one should be wrapped.
370+ // Keep that one so we do wrap.
365371 } else if (prevAdded.canBeReplaced) {
366372 // Though if there aren't any possible extra coverage in the
367373 // previous block compared to this one, we do prefer the smaller
@@ -514,14 +520,23 @@ CoverageInfo _process(
514520
515521 // The extra spaces at the end makes the formatter format better if for
516522 // instance there's comments after this.
523+ bool addedStartBrace = false ;
517524 if (entry.isBlock) {
518525 sb.write ("$extra // Coverage-ignore-block(suite): Not run.\n " );
526+ } else if (entry.allowToWrapInBlock) {
527+ sb.write ("$extra {\n // Coverage-ignore-block(suite): Not run.\n " );
528+ addedStartBrace = true ;
519529 } else {
520530 sb.write ("$extra // Coverage-ignore(suite): Not run.\n " );
521531 }
522532 ignoredIntervalsBuilder? .addIntervalIncludingEnd (
523533 entry.beginToken.charOffset, entry.endToken.charEnd);
524534 from = token.charOffset;
535+ if (addedStartBrace) {
536+ addChunk (from, entry.endToken.charEnd);
537+ from = entry.endToken.charEnd;
538+ sb.write ("\n }" );
539+ }
525540 }
526541 addChunk (from, sourceText.length);
527542 f.writeAsStringSync (sb.toString ());
@@ -888,10 +903,10 @@ class AstIndexerAndIgnoreCollector extends AstIndexer {
888903 /// there is possible coverage but no actual coverage).
889904 bool _checkCommentAndIgnoreCoverage (
890905 Token tokenWithPossibleComment, BeginAndEndTokenParserAstNode ignoreRange,
891- {required bool allowReplace}) {
906+ {required bool allowReplace, bool allowToWrapInBlock = false }) {
892907 return _checkCommentAndIgnoreCoverageWithBeginAndEnd (
893908 tokenWithPossibleComment, ignoreRange.beginToken, ignoreRange.endToken,
894- allowReplace: allowReplace);
909+ allowReplace: allowReplace, allowToWrapInBlock : allowToWrapInBlock );
895910 }
896911
897912 /// Check if there is an ignore comment on [tokenWithPossibleComment] and
@@ -905,7 +920,8 @@ class AstIndexerAndIgnoreCollector extends AstIndexer {
905920 final Token endToken,
906921 {required bool allowReplace,
907922 bool isBlock = false ,
908- bool allowOnBraceStart = false }) {
923+ bool allowOnBraceStart = false ,
924+ bool allowToWrapInBlock = false }) {
909925 if (_hasIgnoreComment (tokenWithPossibleComment, isBlock: isBlock)) {
910926 ignoredStartEnd.addIntervalIncludingEnd (
911927 beginToken.charOffset, endToken.charEnd);
@@ -976,6 +992,7 @@ class AstIndexerAndIgnoreCollector extends AstIndexer {
976992 endToken: endToken,
977993 canBeReplaced: allowReplace,
978994 isBlock: isBlock,
995+ allowToWrapInBlock: allowToWrapInBlock,
979996 ));
980997 }
981998
@@ -1302,7 +1319,9 @@ class _AstIndexerAndIgnoreCollectorBody extends RecursiveParserAstVisitor {
13021319 @override
13031320 void visitThenStatementEnd (ThenStatementEnd node) {
13041321 if (_collector._checkCommentAndIgnoreCoverage (node.beginToken, node,
1305- allowReplace: true )) {
1322+ allowReplace: true ,
1323+ allowToWrapInBlock:
1324+ ! node.beginToken.isA (TokenType .OPEN_CURLY_BRACKET ))) {
13061325 return ;
13071326 }
13081327 super .visitThenStatementEnd (node);
@@ -1556,13 +1575,15 @@ class _CommentOn implements Comparable<_CommentOn> {
15561575 final Token endToken;
15571576 final bool canBeReplaced;
15581577 final bool isBlock;
1578+ final bool allowToWrapInBlock;
15591579
15601580 _CommentOn ({
15611581 required this .commentOnToken,
15621582 required this .beginToken,
15631583 required this .endToken,
15641584 required this .canBeReplaced,
15651585 required this .isBlock,
1586+ required this .allowToWrapInBlock,
15661587 });
15671588
15681589 @override
0 commit comments