Skip to content

Commit

Permalink
Router: align binpacked apply as well if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 25, 2021
1 parent 9fe31a5 commit e5913da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,9 @@ class Router(formatOps: FormatOps) {
val isBracket = open.is[T.LeftBracket]
val indent =
Indent(style.indent.getDefnSite(leftOwner), close, Before)
val align = style.align.getOpenDelimSite(isBracket, true)
val noSplitIndents =
if (align) getOpenParenAlignIndents(close) else Seq(indent)

val bracketPenalty =
if (isBracket) Some(Constants.BracketPenalty) else None
Expand Down Expand Up @@ -1123,7 +1126,7 @@ class Router(formatOps: FormatOps) {
Split(noSplitModification, 0)
.notIf(mustUseNL)
.withPolicy(noSplitPolicy)
.withIndent(indent),
.withIndents(noSplitIndents),
Split(Newline, if (mustUseNL) 0 else nlCost)
.withPolicy(nlDanglePolicy & onelinePolicy & penalizeBrackets)
.withIndent(indent)
Expand All @@ -1137,6 +1140,10 @@ class Router(formatOps: FormatOps) {
val indent = Indent(Num(indentLen), close, Before)
val noSplitIndents =
if (style.binPack.indentCallSiteOnce) Seq.empty
else if (
if (isTuple(leftOwner)) style.align.getOpenParenTupleSite
else style.align.getOpenDelimSite(false, false)
) getOpenParenAlignIndents(close)
else Seq(indent)
def baseNoSplit(implicit fileLine: FileLine) =
Split(Space(style.spaces.inParentheses), 0)
Expand Down
12 changes: 7 additions & 5 deletions scalafmt-tests/src/test/resources/align/DefaultWithAlign.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ object a {
>>>
object a {
foo(bar, baz,
qux)
qux)
}
<<< #2562 tuple, binpack
maxColumn = 13
Expand All @@ -1330,7 +1330,7 @@ object a {
>>>
object a {
(bar, baz,
qux)
qux)
}
<<< #2562 def, binpack
maxColumn = 22
Expand All @@ -1343,7 +1343,8 @@ object a {
>>>
object a {
def a(b: B, c: C,
ddd: DDD) = ???
ddd: DDD) =
???
}
<<< #2562 call, with spaces
maxColumn = 16
Expand Down Expand Up @@ -1402,7 +1403,7 @@ object a {
>>>
object a {
foo( bar, baz,
qux )
qux )
}
<<< #2562 tuple, with spaces, binpack
maxColumn = 14
Expand Down Expand Up @@ -1430,7 +1431,8 @@ object a {
>>>
object a {
def a( b: B, c: C,
ddd: DDD ) = ???
ddd: DDD ) =
???
}
<<< #2562 call, !tuple
maxColumn = 10
Expand Down
14 changes: 8 additions & 6 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1674,15 +1674,15 @@ binPack.preset = true
cache.getOrElseUpdate(name, { x; y; z }, foo, bar)
>>>
cache.getOrElseUpdate(name, { x; y; z },
foo, bar)
foo, bar)
<<< #2633 binPack one arg per line with braces 3
maxColumn = 60
binPack.preset = true
===
cache.getOrElseUpdate(name, { x; y; z }, { x => y; z }, foo, bar)
>>>
cache.getOrElseUpdate(name, { x; y; z }, { x => y; z }, foo,
bar)
bar)
<<< #2633 binPack with multiline arg, always
maxColumn = 80
indent.callSite = 2
Expand All @@ -1697,8 +1697,8 @@ object a {
object a {
val cls =
Select(Select(Select(Select(Select(Select(Ident(nme.ROOTPKG), nme.scala_),
scalajs), js), nme.annotation, x, y, z), internal_, a, b, c),
wasPublicBeforeTyperXxx)
scalajs), js), nme.annotation, x, y, z),
internal_, a, b, c), wasPublicBeforeTyperXxx)
}
<<< #2633 binPack with multiline arg, oneline
maxColumn = 80
Expand Down Expand Up @@ -1743,7 +1743,8 @@ object a {
symForName
.getAnnotation(JSNameAnnotation).fold {
sym.addAnnotation(JSNameAnnotation,
Literal(Constant(jsInterop.defaultJSNameOf(symForName))))
Literal(Constant(jsInterop.defaultJSNameOf(
symForName))))
} { annot =>
sym.addAnnotation(annot)
}
Expand Down Expand Up @@ -1772,7 +1773,8 @@ object a {
symForName
.getAnnotation(JSNameAnnotation).fold {
sym.addAnnotation(JSNameAnnotation,
Literal(Constant(jsInterop.defaultJSNameOf(symForName))))
Literal(Constant(jsInterop.defaultJSNameOf(
symForName))))
} { annot =>
sym.addAnnotation(annot)
}
Expand Down
8 changes: 4 additions & 4 deletions scalafmt-tests/src/test/resources/default/TypeArguments.stat
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder:
>>>
object a {
def deploy[M[_[_]]: FunctorK, F[_], State, Event: PersistentEncoder: PersistentDecoder,
K: KeyEncoder: KeyDecoder] = ???
K: KeyEncoder: KeyDecoder] = ???
def props[
M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: PersistentDecoder]() =
???
Expand All @@ -453,7 +453,7 @@ def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder:
>>>
object a {
def deploy[M[_[_]]: FunctorK, F[_], State, Event: PersistentEncoder: PersistentDecoder,
K: KeyEncoder: KeyDecoder] = ???
K: KeyEncoder: KeyDecoder] = ???
def props[
M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: PersistentDecoder]() =
???
Expand All @@ -471,7 +471,7 @@ def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder:
>>>
object a {
def deploy[M[_[_]]: FunctorK, F[_], State, Event: PersistentEncoder: PersistentDecoder,
K: KeyEncoder: KeyDecoder] = ???
K: KeyEncoder: KeyDecoder] = ???
def props[
M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: PersistentDecoder]() =
???
Expand All @@ -489,7 +489,7 @@ def props[M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder:
>>>
object a {
def deploy[M[_[_]]: FunctorK, F[_], State, Event: PersistentEncoder: PersistentDecoder,
K: KeyEncoder: KeyDecoder] = ???
K: KeyEncoder: KeyDecoder] = ???
def props[
M[_[_]], F[_]: Async, I: KeyDecoder, State, Event: PersistentEncoder: PersistentDecoder]() =
???
Expand Down

0 comments on commit e5913da

Please sign in to comment.