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 left non-whitespace token.
The whitespace tokens between left and right.
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 or unknown integer StateColumn.
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.
The decision made by Router.
Assigns splits to format tokens.
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.
For convenience when experimenting with different hashing strategies.
Stateless helper functions on scala.meta.Token.
Stateless helper functions on scala.meta.Tree.
(ugly) Utility to collect data about formatter.
(ugly) Utility to collect data about formatter.
Only used during development.
Debugging utility.
Indent up to the column of the left token.
Indent up to the column of the left token.
Example: the opening parenthesis below indents by StateColumn.
foobar(arg1, arg2)
Custom hash code for token.
Custom hash code for token.
The default hashCode is slow because it prevents conflicts between tokens from different source files. We only care about getting a unique identifier for the token inside this source file.
The hash code works like this this: Top 8 bits go to privateTag, a unique identifier for the tokens class. Next 28 bits go to the tokens **start** offset byte. Final 28 bits go to the tokens **end** offset byte.
The only chance for collision is if two empty length tokens with the same type lie next to each other. @xeno-by said this should not happen.