Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/src/front_end/piece_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ final class PieceWriter {
if (comments.isEmpty) return const [];

var leadingComments = <Piece>[];
var afterHanging = false;
for (var i = 0; i < comments.length; i++) {
var comment = comments[i];

Expand All @@ -411,12 +412,16 @@ final class PieceWriter {

var piece = commentPiece(comment, trailingWhitespace);

if (comments.isHanging(i)) {
if (!afterHanging && comments.isHanging(i)) {
// Attach it to the previous CodePiece.
_previousCode!.addHangingComment(piece);
} else {
// Add it to the list of leading comments for the upcoming token.
leadingComments.add(piece);

// Once we've found a single non-hanging comment, all subsequent ones
// must also be non-hanging since they follow it.
afterHanging = true;
}
}

Expand Down
47 changes: 47 additions & 0 deletions test/tall/regression/1600/1667.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
>>>
/*Debugger:stepOver*/
void main() {
/*bl*/ /*sl:1*/ var data = [1, 2, 3];
for (
// comment forcing formatting
/*sl:3*/ /*sl:5*/ /*sl:7*/ /*sl:8*/ var datapoint
// comment forcing formatting
in
// comment forcing formatting
/*sl:2*/ data
// comment forcing formatting
) {
/*sl:4*/ /*sl:6*/ /*sl:8*/ print(datapoint);
}
/*sl:9 */ print('Done');
}
<<<
/*Debugger:stepOver*/
void main() {
/*bl*/ /*sl:1*/
var data = [1, 2, 3];
for (
// comment forcing formatting
/*sl:3*/ /*sl:5*/ /*sl:7*/ /*sl:8*/ var datapoint
// comment forcing formatting
in
// comment forcing formatting
/*sl:2*/ data
// comment forcing formatting
) {
/*sl:4*/ /*sl:6*/ /*sl:8*/
print(datapoint);
}
/*sl:9 */
print('Done');
}
>>> Minimal repro.
main() {
for (
/* 1 */ /* 2 */ datapoint in data) {}
}
<<<
main() {
for (
/* 1 */ /* 2 */ datapoint in data) {}
}