Skip to content

Commit

Permalink
Router: handle self-type whether it ends in => (#3602)
Browse files Browse the repository at this point in the history
Previously, self-type ends just before the `=>` but in the next version
of scalameta it will end on `=>` instead. Let's handle both cases.
  • Loading branch information
kitbellew authored Aug 1, 2023
1 parent a3733b4 commit bc1b768
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,14 @@ class Router(formatOps: FormatOps) {
else Some(false)
(arrow, Some(arrow.left), 0, nlOnly)
case _ =>
selfAnnotationLast match {
case Some(anno) =>
val arrow = leftOwner.tokens.find(_.is[T.RightArrow])
val expire = arrow.getOrElse(anno)
val indent = style.indent.main
(tokens(expire), arrow, indent, Some(isSelfAnnotationNL))
case _ =>
(null, None, 0, None)
val annoOpt = selfAnnotationLast.map { anno =>
val indent = style.indent.main
val annoFT = tokens(anno)
val arrow = annoFT.left.is[T.RightArrow]
val expire = if (arrow) annoFT else next(nextNonComment(annoFT))
(expire, Some(expire.left), indent, Some(isSelfAnnotationNL))
}
annoOpt.getOrElse { (null, None, 0, None) }
}
val lambdaPolicy =
if (lambdaExpire == null) null
Expand Down Expand Up @@ -446,11 +445,14 @@ class Router(formatOps: FormatOps) {
.withIndent(style.indent.main, endIndent, After)
)

case FormatToken(T.RightArrow() | T.ContextArrow(), right, _)
if leftOwner.is[Term.FunctionTerm] ||
leftOwner.is[Term.PolyFunction] ||
(leftOwner.is[Template] &&
leftOwner.parent.exists(_.is[Term.NewAnonymous])) =>
case FormatToken(_: T.RightArrow | _: T.ContextArrow, right, _)
if (leftOwner match {
case _: Term.FunctionTerm | _: Term.PolyFunction => true
case t: Template => t.parent.exists(_.is[Term.NewAnonymous])
case t: Self =>
t.parent.exists(_.parent.exists(_.is[Term.NewAnonymous]))
case _ => false
}) =>
val (endOfFunction, expiresOn) = leftOwner match {
case t: Term.FunctionTerm => functionExpire(t)
case t => getLastNonTrivialToken(t) -> ExpiresOn.Before
Expand Down

0 comments on commit bc1b768

Please sign in to comment.