From f000d9c4518dccd1e337b1806008e071a5b74f71 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 26 Nov 2024 00:59:41 -0800 Subject: [PATCH] FormatOps: extend getSlbEndOnLeft to LeftBrace --- .../org/scalafmt/internal/FormatOps.scala | 31 ++++++++++++------- .../test/scala/org/scalafmt/FormatTests.scala | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 260be8e035..e398bde270 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -94,18 +94,25 @@ class FormatOps( ) start else null } - case _: T.LeftBrace => start.left match { - case _: T.RightParen - if start.leftOwner.is[Member.SyntaxValuesClause] && - start.rightOwner.parent.exists { - case p: Tree.WithBody => p.body eq start.rightOwner - case _ => false - } => null - case _: T.Interpolation.SpliceStart - if style.newlines.inInterpolation eq - Newlines.InInterpolation.allow => null - case _ => start - } + case _: T.LeftBrace if (start.left match { + case _: T.CloseDelim => + (start.leftOwner match { + case _: Member.SyntaxValuesClause => true + case t: Term.Block => t.parent.is[Term.ArgClause] + case _ => false + }) && + (start.rightOwner match { + case _: Term.ArgClause => true + case t => t.parent.exists { + case p: Tree.WithBody => p.body eq start.rightOwner + case _: Term.ArgClause => true + case _ => false + } + }) + case _: T.Interpolation.SpliceStart => + style.newlines.inInterpolation eq Newlines.InInterpolation.allow + case _ => false + }) => null case _: T.RightBracket if start.left.is[T.RightBracket] => null case _: T.LeftBracket => null case _: T.Dot => start.rightOwner match { diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index a25dc2a92b..eb88a5a5f3 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -144,7 +144,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { val explored = Debug.explored.get() logger.debug(s"Total explored: $explored") if (!onlyUnit && !onlyManual) - assertEquals(explored, 1183844, "total explored") + assertEquals(explored, 1183838, "total explored") val results = debugResults.result() // TODO(olafur) don't block printing out test results. // I don't want to deal with scalaz's Tasks :'(