Skip to content

Commit

Permalink
FormatOps: return FormatToken in findFirstOnRight
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed May 15, 2024
1 parent b12dd7a commit 3bd7e95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ class FormatOps(

def findFirstOnRight[A](start: FormatToken, end: T)(implicit
classifier: Classifier[T, A],
): Option[T] = findFirst(start, end.start)(x => classifier(x.right))
.map(_.right)
): Option[FormatToken] = findFirst(start, end.start)(x => classifier(x.right))

final def rhsOptimalToken(start: FormatToken, end: Int = Int.MaxValue): T =
findTokenWith(start, next) { start =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,14 +1141,14 @@ class Router(formatOps: FormatOps) {
case NlClosedOnOpen.Yes => getDanglePolicy
case NlClosedOnOpen.No => NoPolicy
}
def nlOnelinePolicy = nextComma
.map(x => splitOneArgPerLineAfterCommaOnBreak(x.right))

Seq(
noSplit.withIndents(noSplitIndents),
Split(nlMod, if (slbOrNL) 0 else nlCost).withIndent(indent)
.withPolicy(nlPolicy & penalizeBrackets).andPolicyOpt(
nextComma.map(splitOneArgPerLineAfterCommaOnBreak),
!oneline,
),
.withPolicy(nlPolicy & penalizeBrackets)
.andPolicyOpt(nlOnelinePolicy, !oneline),
)
}

Expand All @@ -1174,6 +1174,7 @@ class Router(formatOps: FormatOps) {
val nlOnly = nlOpen && !singleLineOnly

def findComma(ft: FormatToken) = findFirstOnRight[T.Comma](ft, close)
.map(_.right)

val oneline = style.binPack.callSiteFor(open) == BinPack.Site.Oneline
val nextCommaOneline =
Expand Down

0 comments on commit 3bd7e95

Please sign in to comment.