Skip to content

Commit

Permalink
BestFirstSearch: define getNext()
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 20, 2024
1 parent ac849f9 commit 3b7ef5a
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ private class BestFirstSearch private (range: Set[Range])(implicit
}

actualSplit.foreach { split =>
style.runner.event(FormatEvent.Enqueue(split))
if (optimalNotFound) processNextState(curr.next(split, allAltAreNL))
if (optimalNotFound)
processNextState(getNext(curr, split, allAltAreNL))
else sendEvent(split)
}
}
}
Expand All @@ -184,6 +185,16 @@ private class BestFirstSearch private (range: Set[Range])(implicit
null
}

private def sendEvent(split: Split): Unit = initStyle.runner
.event(FormatEvent.Enqueue(split))

private def getNext(state: State, split: Split, allAltAreNL: Boolean)(implicit
style: ScalafmtConfig,
): State = {
sendEvent(split)
state.next(split, nextAllAltAreNL = allAltAreNL)
}

private def killOnFail(
opt: OptimalToken,
)(implicit nextState: State): State = {
Expand Down Expand Up @@ -249,8 +260,8 @@ private class BestFirstSearch private (range: Set[Range])(implicit
case Seq(split) =>
if (split.isNL) state
else {
style.runner.event(FormatEvent.Enqueue(split))
val nextState = state.next(split, nextAllAltAreNL = false)
implicit val nextState: State =
getNext(state, split, allAltAreNL = false)
traverseSameLine(nextState)
}
case ss
Expand All @@ -267,8 +278,7 @@ private class BestFirstSearch private (range: Set[Range])(implicit
state: State,
)(implicit style: ScalafmtConfig, queue: StateQueue): State = splits match {
case Seq(split) if !split.isNL =>
style.runner.event(FormatEvent.Enqueue(split))
val nextState = state.next(split, nextAllAltAreNL = false)
val nextState: State = getNext(state, split, allAltAreNL = false)
if (nextState.split.cost > 0) state
else if (nextState.depth >= tokens.length) nextState
else {
Expand Down

0 comments on commit 3b7ef5a

Please sign in to comment.