@@ -146,6 +146,10 @@ public class PrettyPrinter {
146
146
/// enabled (see ``isBreakingSuppressed``).
147
147
private var allowSuppressedDiscretionaryBreaks = false
148
148
149
+ /// Overrides break suppression for line or doc comments, or similar cases where a line break is required.
150
+ /// Reset after handling the break.
151
+ private var shouldOverrideBreakSuppression = false
152
+
149
153
/// The computed indentation level, as a number of spaces, based on the state of any unclosed
150
154
/// delimiters and whether or not the current line is a continuation line.
151
155
private var currentIndentation : [ Indent ] {
@@ -426,7 +430,8 @@ public class PrettyPrinter {
426
430
case . soft( _, let discretionary) :
427
431
// A discretionary newline (i.e. from the source) should create a line break even if the
428
432
// rules for breaking are disabled.
429
- overrideBreakingSuppressed = discretionary && allowSuppressedDiscretionaryBreaks
433
+ overrideBreakingSuppressed =
434
+ shouldOverrideBreakSuppression || ( discretionary && allowSuppressedDiscretionaryBreaks)
430
435
mustBreak = true
431
436
case . hard:
432
437
// A hard newline must always create a line break, regardless of the context.
@@ -455,6 +460,7 @@ public class PrettyPrinter {
455
460
outputBuffer. enqueueSpaces ( size)
456
461
lastBreak = false
457
462
}
463
+ shouldOverrideBreakSuppression = false
458
464
459
465
// Print out the number of spaces according to the size, and adjust spaceRemaining.
460
466
case . space( let size, _) :
@@ -472,7 +478,7 @@ public class PrettyPrinter {
472
478
473
479
case . comment( let comment, let wasEndOfLine) :
474
480
lastBreak = false
475
-
481
+ shouldOverrideBreakSuppression = comment . kind == . docLine || comment . kind == . line
476
482
if wasEndOfLine {
477
483
if !( canFit ( comment. length) || isBreakingSuppressed) {
478
484
diagnose ( . moveEndOfLineComment, category: . endOfLineComment)
0 commit comments