Implements best first search to find optimal formatting.
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.
One layer of indentation, created by an opening (, {, etc.
One layer of indentation, created by an opening (, {, etc.
Indent is parameterized by some Length to allow splits from Router to be memoized. If the length field was int, we would have to eagerly evaluate the indentation for state columns, which may be different depending on the formatting we choose.
Can be a known number Num (used in State) or unknown integer StateColumn (used in Split).
lengt of indentation, can be negative (in rare cases, with deeply nested terms with no newlines).
Until which token does this indentation stay?
If Right, then expires when expire is curr.right, otherwise curr.left in BestFirstSearch.
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.
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?
Does this split overflow the column limit?
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.