@@ -3386,12 +3386,31 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
3386
3386
private func appendToken( _ token: Token ) {
3387
3387
if let last = tokens. last {
3388
3388
switch ( last, token) {
3389
- case ( . comment( let c1, _) , . comment( let c2, _) )
3390
- where c1. kind == . docLine && c2. kind == . docLine:
3391
- var newComment = c1
3392
- newComment. addText ( c2. text)
3393
- tokens [ tokens. count - 1 ] = . comment( newComment, wasEndOfLine: false )
3394
- return
3389
+ case ( . break( . same, _, . soft( let count, _) ) , . comment( let c2, _) )
3390
+ where count == 1 && ( c2. kind == . docLine || c2. kind == . line) :
3391
+ // we are search for the pattern of [line comment] - [soft break 1] - [line comment]
3392
+ // where the comment type is the same; these can be merged into a single comment
3393
+ if let nextToLast = tokens. dropLast ( ) . last,
3394
+ case let . comment( c1, false ) = nextToLast,
3395
+ c1. kind == c2. kind
3396
+ {
3397
+ var mergedComment = c1
3398
+ mergedComment. addText ( c2. text)
3399
+ tokens. removeLast ( ) // remove the soft break
3400
+ // replace the original comment with the merged one
3401
+ tokens [ tokens. count - 1 ] = . comment( mergedComment, wasEndOfLine: false )
3402
+
3403
+ // need to fix lastBreakIndex because we just removed the last break
3404
+ lastBreakIndex = tokens. lastIndex ( where: {
3405
+ switch $0 {
3406
+ case . break: return true
3407
+ default : return false
3408
+ }
3409
+ } )
3410
+ canMergeNewlinesIntoLastBreak = false
3411
+
3412
+ return
3413
+ }
3395
3414
3396
3415
// If we see a pair of spaces where one or both are flexible, combine them into a new token
3397
3416
// with the maximum of their counts.
0 commit comments