Skip to content

Commit

Permalink
Router: do not skip indent if binpacking an infix
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 24, 2021
1 parent e2e14a6 commit 309fc42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,15 @@ class Router(formatOps: FormatOps) {

val indentLen = style.indent.callSite
val indent = Indent(Num(indentLen), close, Before)
val firstArg = argsOpt.flatMap(_.headOption)
val noNoSplitIndents = nlOnly ||
style.binPack.indentCallSiteOnce ||
isSingleArg && oneline && !needOnelinePolicy ||
!firstArg.exists(isInfixApp) && (style.binPack.indentCallSiteOnce ||
isSingleArg && oneline && !needOnelinePolicy) ||
!isBracket && getAssignAtSingleArgCallSite(leftOwner).isDefined
val noSplitIndents =
if (noNoSplitIndents) Nil
else if (style.binPack.indentCallSiteOnce && firstArg.isDefined)
Seq(Indent(Num(indentLen), firstArg.get.tokens.last, After))
else if (
if (isTuple(leftOwner)) style.align.getOpenParenTupleSite
else style.align.getOpenDelimSite(false, false)
Expand Down Expand Up @@ -1417,14 +1420,14 @@ class Router(formatOps: FormatOps) {
decideNewlinesOnlyBeforeCloseOnBreak(t)
case _ => NoPolicy
}
val indentCallSiteOnce =
style.binPack.indentCallSiteOnce && callSite
val indent = if (indentCallSiteOnce) style.indent.callSite else 0
val indent =
if (style.binPack.indentCallSiteOnce && callSite) {
val indentEnd = if (isInfixApp(nextArg)) lastFT.left else right
Indent(style.indent.callSite, indentEnd, After)
} else Indent.Empty
Seq(
Split(Space, 0).withSingleLine(endOfSingleLineBlock(optFT)),
Split(Newline, 1)
.withIndent(indent, right, After)
.withPolicy(nlPolicy)
Split(Newline, 1).withIndent(indent).withPolicy(nlPolicy)
)
}
}
Expand Down
24 changes: 12 additions & 12 deletions scalafmt-tests/src/test/resources/scalajs/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ optDef.getOrElse {
>>>
optDef.getOrElse {
abort(foo &&
bar)
bar)
abort(foo &&
bar,
baz)
Expand Down Expand Up @@ -513,23 +513,23 @@ optDef.getOrElse {
>>>
optDef.getOrElse {
abort(foo &&
bar)
bar)
abort(foo &&
bar,
bar,
foo &&
bar, baz)
bar, baz)
abort(abort(foo &&
bar,
bar,
foo &&
bar,
bar,
abort(foo &&
bar,
bar,
foo &&
bar, baz)),
bar, baz)),
abort(foo &&
bar,
bar,
foo &&
bar, baz))
bar, baz))
}
<<< binpack with non-top-level-only infix, afterInfix=some
maxColumn = 20
Expand All @@ -546,7 +546,7 @@ optDef.getOrElse {
>>>
optDef.getOrElse {
abort(fooFoo &&
barBar)
barBar)
abort(fooFoo &&
barBar,
bazBaz)
Expand All @@ -566,7 +566,7 @@ optDef.getOrElse {
>>>
optDef.getOrElse {
abort(fooFoo &&
barBar)
barBar)
abort(fooFoo &&
barBar,
bazBaz)
Expand Down

0 comments on commit 309fc42

Please sign in to comment.