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 48b3fd0 commit a71ee0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 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

0 comments on commit a71ee0b

Please sign in to comment.