Skip to content

Commit

Permalink
Router: tighten range for parent-ctors policy
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed May 14, 2024
1 parent 26a244e commit 8058ef6
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -738,21 +738,19 @@ class Router(formatOps: FormatOps) {
_,
WithTemplateOnLeft(template),
) =>
def expire = getTemplateGroups(template)
.flatMap(_.last.headOption.flatMap(_.tokens.headOption))
.getOrElse(getLastToken(leftOwner))
def forceNewlineBeforeExtends = Policy.before(expire) {
case Decision(FormatToken(_, soft.ExtendsOrDerives(), m), s)
if m.rightOwner.parent.contains(leftOwner) =>
s.filter(x => x.isNL && !x.isActiveFor(SplitTag.OnelineWithChain))
}
val policy =
if (style.binPack.keepParentConstructors) None
else template.tokens.headOption.map { head =>
val policyEnd = Policy.End.Before(head)
delayedBreakPolicy(policyEnd)(forceNewlineBeforeExtends)
if (style.binPack.keepParentConstructors || template.pos.isEmpty)
NoPolicy
else {
val expire = templateDerivesOrCurlyOrLastNonTrivial(template)
val forceNewlineBeforeExtends = Policy.before(expire) {
case Decision(FormatToken(_, soft.ExtendsOrDerives(), m), s)
if m.rightOwner eq template =>
s.filter(x => x.isNL && !x.isActiveFor(SplitTag.OnelineWithChain))
}
delayedBreakPolicyBefore(expire)(forceNewlineBeforeExtends)
}
Seq(Split(Space, 0).withPolicyOpt(policy))
Seq(Split(Space, 0).withPolicy(policy))
// DefDef
case FormatToken(_: T.KwDef, _: T.Ident, _) => Seq(Split(Space, 0))
case FormatToken(_: T.Equals, _, DefValAssignLeft(rhs)) =>
Expand Down

0 comments on commit 8058ef6

Please sign in to comment.