Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: bp=oneline multi-line arg ends before ) #4043

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
}
Loading