Skip to content

Commit 54a423d

Browse files
committed
Print double line break before applied block
```scala foo // make sure this line is printed to avoid applying the block to foo { ... }.apply(...) ```
1 parent 6b8d0ba commit 54a423d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,15 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
440440
}
441441

442442
def printStats(stats: List[Tree], expr: Tree): Unit = {
443-
def printSeparator(nextStats: List[Tree]) = {
443+
def printSeparator(next: Tree): Unit = {
444444
// Avoid accidental application of opening `{` on next line with a double break
445-
val next = if (nextStats.isEmpty) expr else nextStats.head
446445
next match {
447446
case Term.Block(DefDef("while$" | "doWhile$", _, _, _, _) :: Nil, _) => this += lineBreak()
448447
case Term.Block(_, _) => this += doubleLineBreak()
449448
case Term.Inlined(_, _, _) => this += doubleLineBreak()
449+
case Term.Select(qual, _, _) => printSeparator(qual)
450+
case Term.Apply(fn, _) => printSeparator(fn)
451+
case Term.TypeApply(fn, _) => printSeparator(fn)
450452
case _ => this += lineBreak()
451453
}
452454
}
@@ -455,7 +457,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
455457
printTree(expr)
456458
case x :: xs =>
457459
printTree(x)
458-
printSeparator(xs)
460+
printSeparator(if (xs.isEmpty) expr else xs.head)
459461
printSeparated(xs)
460462
}
461463

0 commit comments

Comments
 (0)