@@ -146,6 +146,10 @@ public class PrettyPrinter {
146146 /// enabled (see ``isBreakingSuppressed``).
147147 private var allowSuppressedDiscretionaryBreaks = false
148148
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+
149153 /// The computed indentation level, as a number of spaces, based on the state of any unclosed
150154 /// delimiters and whether or not the current line is a continuation line.
151155 private var currentIndentation : [ Indent ] {
@@ -426,7 +430,8 @@ public class PrettyPrinter {
426430 case . soft( _, let discretionary) :
427431 // A discretionary newline (i.e. from the source) should create a line break even if the
428432 // rules for breaking are disabled.
429- overrideBreakingSuppressed = discretionary && allowSuppressedDiscretionaryBreaks
433+ overrideBreakingSuppressed =
434+ shouldOverrideBreakSuppression || ( discretionary && allowSuppressedDiscretionaryBreaks)
430435 mustBreak = true
431436 case . hard:
432437 // A hard newline must always create a line break, regardless of the context.
@@ -455,6 +460,7 @@ public class PrettyPrinter {
455460 outputBuffer. enqueueSpaces ( size)
456461 lastBreak = false
457462 }
463+ shouldOverrideBreakSuppression = false
458464
459465 // Print out the number of spaces according to the size, and adjust spaceRemaining.
460466 case . space( let size, _) :
@@ -472,7 +478,7 @@ public class PrettyPrinter {
472478
473479 case . comment( let comment, let wasEndOfLine) :
474480 lastBreak = false
475-
481+ shouldOverrideBreakSuppression = comment . kind == . docLine || comment . kind == . line
476482 if wasEndOfLine {
477483 if !( canFit ( comment. length) || isBreakingSuppressed) {
478484 diagnose ( . moveEndOfLineComment, category: . endOfLineComment)
0 commit comments