Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: fix beforeOpenParenDefnSite = unfold #3506

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ class Router(formatOps: FormatOps) {
case Newlines.unfold =>
val rightParent = rightOwner.parent.get
val slbEnd =
if (defn) beforeDefRhs.fold(getLastToken(rightParent))(_.left)
if (defn)
beforeDefRhs
.fold(getLastToken(rightParent))(prevNonComment(_).left)
else getLastToken(getLastCall(rightParent))
val multipleArgs = isSeqMulti(getArgs(next(ft).meta.leftOwner))
val nft = tokens.tokenAfter(close)
Expand Down
12 changes: 12 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4590,3 +4590,15 @@ object Test:
catch
case _: RuntimeException => 2
case _: Exception => 3
<<< #3497
newlines.beforeOpenParenDefnSite = null
===
extension (s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
>>>
extension (s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
12 changes: 12 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4397,3 +4397,15 @@ object Test:
catch
case _: RuntimeException => 2
case _: Exception => 3
<<< #3497
newlines.beforeOpenParenDefnSite = fold
===
extension (s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
>>>
extension(s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
12 changes: 12 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4631,3 +4631,15 @@ object Test:
catch
case _: RuntimeException => 2
case _: Exception => 3
<<< #3497
newlines.beforeOpenParenDefnSite = keep
===
extension (s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
>>>
extension(s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
Original file line number Diff line number Diff line change
Expand Up @@ -4733,3 +4733,15 @@ object Test:
2
case _: Exception =>
3
<<< #3497
newlines.beforeOpenParenDefnSite = unfold
===
extension (s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???
>>>
extension(s: String)
/** ... */
def foo(): Unit = ???
def bar(): Unit = ???