Skip to content

Commit

Permalink
Router: implement binPack.indentCallSiteSingleArg
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 28, 2022
1 parent 0e368dc commit 69bad29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ class Router(formatOps: FormatOps) {
!isBracket && getAssignAtSingleArgCallSite(leftOwner).isDefined
val noSplitIndents =
if (noNoSplitIndents) Nil
else if (isSingleArg && !style.binPack.indentCallSiteSingleArg) Nil
else if (style.binPack.indentCallSiteOnce) {
@tailrec
def iter(tree: Tree): Option[T] = tree.parent match {
Expand Down Expand Up @@ -1349,7 +1350,7 @@ class Router(formatOps: FormatOps) {
SingleLineBlock(slbEnd, noSyntaxNL = true)
}
} else penalizeNewlinesPolicy
val indentOncePolicy =
def indentOncePolicy =
if (style.binPack.indentCallSiteOnce) {
val trigger = getIndentTrigger(leftOwner)
Policy.on(close) {
Expand All @@ -1362,7 +1363,7 @@ class Router(formatOps: FormatOps) {
.withOptimalTokenOpt(opt)
.withPolicy(noSplitPolicy)
.andPolicy(unindentPolicy, !isSingleArg || noSplitIndents.isEmpty)
.andPolicy(indentOncePolicy)
.andPolicy(indentOncePolicy, noSplitIndents.isEmpty)
}

val nlPolicy = {
Expand Down
20 changes: 10 additions & 10 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -2039,14 +2039,14 @@ object a {
>>>
object a {
val ref = foo(bar((_, _) =>
baz1 { qux1 =>
noop1
} baz2 { qux2 =>
noop2
} baz3 //
{ qux3 =>
noop3
} baz4 { qux4 =>
noop4
}))
baz1 { qux1 =>
noop1
} baz2 { qux2 =>
noop2
} baz3 //
{ qux3 =>
noop3
} baz4 { qux4 =>
noop4
}))
}

0 comments on commit 69bad29

Please sign in to comment.