Skip to content

Commit

Permalink
BestFirstSearch: allow block close go past range
Browse files Browse the repository at this point in the history
In reality, that's what has been happening so far since we used an exact
comparison on `stop`.
  • Loading branch information
kitbellew committed Nov 13, 2024
1 parent 7e46a26 commit e69f0ad
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ private class BestFirstSearch private (range: Set[Range])(implicit

var stats = new StateStats(tokens, initStyle.runner)

private def getBlockCloseToRecurse(ft: FT, stop: T)(implicit
private def getBlockCloseToRecurse(ft: FT)(implicit
style: ScalafmtConfig,
): Option[T] = getEndOfBlock(ft, parensToo = true).collect {
case close if close.left != stop && {
// Block must span at least 3 lines to be worth recursing.
tokens.width(ft, close) > style.maxColumn * 3
} => close.left
// Block must span at least 3 lines to be worth recursing.
case close if tokens.width(ft, close) > style.maxColumn * 3 => close.left
}

private val memo = mutable.Map.empty[Long, Option[State]]
Expand Down Expand Up @@ -111,7 +109,7 @@ private class BestFirstSearch private (range: Set[Range])(implicit
noOptZoneOrBlock.isEmpty || !optimizer.recurseOnBlocks
val blockCloseState =
if (noBlockClose) None
else getBlockCloseToRecurse(splitToken, stop)
else getBlockCloseToRecurse(splitToken)
.flatMap(shortestPathMemo(curr, _, depth + 1, isOpt))
if (blockCloseState.nonEmpty) blockCloseState
.foreach(_.foreach(Q.enqueue))
Expand Down

0 comments on commit e69f0ad

Please sign in to comment.