Skip to content

Commit

Permalink
Router: bp=oneline multi-line arg ends before )
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 8, 2024
1 parent ac47cb1 commit 2868b92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,7 @@ class Router(formatOps: FormatOps) {
if (binPack eq BinPack.Site.Never) None
else Some {
val lastFT = getLast(nextArg)
val lastTok = lastFT.left
val loEnd = leftOwner.tokens.last.end
val oneline = binPack == BinPack.Site.Oneline
val nextCommaOrParen = findFirst(lastFT, loEnd) {
Expand Down Expand Up @@ -1434,10 +1435,10 @@ class Router(formatOps: FormatOps) {
case _ if callSite =>
def delayBreakBefore(token: T): Policy = {
// force break if multiline and if there's no other break
val lastEnd = lastFT.left.end
delayedBreakPolicy(Policy.End > lastEnd)(
val lastEnd = lastTok.end
delayedBreakPolicy(Policy.End == lastEnd)(
Policy.RelayOnSplit { case (s, nextft) =>
s.isNL && nextft.left.end > lastEnd // don't need anymore
s.isNL && nextft.right.end > lastEnd // don't need anymore
}(decideNewlinesOnlyBeforeToken(token), NoPolicy),
)
}
Expand All @@ -1461,7 +1462,7 @@ class Router(formatOps: FormatOps) {
val indentOncePolicy = Policy ?
(callSite && style.binPack.indentCallSiteOnce) && {
val trigger = getIndentTrigger(leftOwner)
Policy.on(lastFT.left, prefix = "IND1") {
Policy.on(lastTok, prefix = "IND1") {
case Decision(FormatToken(LeftParenOrBracket(), _, m), s)
if isArgClauseSite(m.leftOwner) =>
s.map(x => if (x.isNL) x else x.switch(trigger, true))
Expand Down
9 changes: 3 additions & 6 deletions scalafmt-tests/src/test/resources/scalajs/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,7 @@ object a {
js.MethodDef(flags, methodIdent, originalName, jsParams, resultType,
Some {
genApplyMethod(genLoadModule(moduleClass), m, jsParams.map(_.ref))
})(
OptimizerHints.empty, Unversioned)
})(OptimizerHints.empty, Unversioned)
}
<<< nested with oneline, keep
newlines.source = keep
Expand All @@ -1042,8 +1041,7 @@ object a {
js.MethodDef(flags, methodIdent, originalName, jsParams, resultType,
Some {
genApplyMethod(genLoadModule(moduleClass), m, jsParams.map(_.ref))
})(
OptimizerHints.empty, Unversioned)
})(OptimizerHints.empty, Unversioned)
}
<<< oneline with keep and select after
preset = default
Expand All @@ -1068,7 +1066,6 @@ object a {
js.Dynamic.literal(
`type` = "button",
value = "Reset"
))
.click(() => reset())
)).click(() => reset())
}
}

0 comments on commit 2868b92

Please sign in to comment.