The decision made by Router.
Helper functions for generating splits/policies for a given tree.
Two adjacent non-whitespace tokens.
Two adjacent non-whitespace tokens.
Consider a FormatToken as a node in a search graph and Split are the edges. The format tokens remain unchanged after formatting, while the splits are changed.
The left non-whitespace token.
The right non-whitespace token.
Extra information about the token
Produces formatted output from sequence of splits.
A split representing a newline.
The decision made by Router.
Minimal implementation of the PriorityQueue's functions needed.
Minimal implementation of the PriorityQueue's functions needed.
We use java.util.PriorityQueue
to enable usage under GraalVM. The
native-image compiler is unable to work with
scala.collection.mutable.PriorityQueue
currently.
the values inside the queue
Assigns splits to format tokens.
Assigns splits to format tokens.
NOTE(olafurpg). The pattern match in this file has gotten out of hand. It's difficult even for myself to keep track of what's going on in some cases, especially around applications and lambdas. I'm hoping to sunset this file along with BestFirstSearch in favor of https://github.com/scalameta/scalafmt/issues/917
A Split is the whitespace between two non-whitespace tokens.
A Split is the whitespace between two non-whitespace tokens.
Consider a split to be an edge in a search graph and FormatToken are the nodes.
NB: there's a historical inconsistency in how splits are sorted; when they are initially considered, cost is the primary factor (and hence, because of stable sort, earlier split with the same cost will take precedence). However, when a search state is added into the priority queue, preference is given to states with lower cost, further token and, unlike above, a LATER line defining the split.
A possible reason for the latter is to give those "secondary" splits a chance to move through the BestFirstSearch algorithm, as otherwise a sequence of primary splits might end up as the winning solution even if it exceeds the maxColumn margins, because a secondary split was deemed unlikely to win and moved to a backup priority queue.
Is this a space, no space, newline or 2 newlines?
How good is this output? Lower is better.
Does this add indentation?
How does this split affect other later splits?
For debugging, to retrace from which case in Router this split originates.
A partial formatting solution up to splits.length number of tokens.
The decision made by Router.
Used by Policy to enforce non-local formatting.