Conversation
3e5e96f to
b9ef5bc
Compare
nilscrm
reviewed
May 7, 2026
nilscrm
reviewed
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The old formatter had a number of limitations – perhaps most notably, it was very 'greedy'; when a syntax node was deciding to be multiline or not, it would only check if it would fit in the max width minus what was written so far onto the line. This means it wouldn't take into account anything after it on the same line, and so quite often things would be formatted like
This occured because when it was printing the parameter list, it only looked at the length of
fn some_function(...), which was below the max limit, and so it printed it on a single line. Only once it got to the return type did it realize something was going over the maximum width, so it breaks the return type, which looks really bad.In the new formatting algorithm, each node receives information about what comes both before and after it on the same line, and decides whether or not to break on that basis. This means that the above example will instead get formatted as
Which is a lot nicer. This happens because the parameter list can see that the return type after it would cause the line to overflow.
If, on the other hand, the parameters were fine, and it was the return type that was super long, it would get formatted like so:
This is because each syntax node can either configure the order in which its children will break, or have it be automatic, in which case larger children will get broken first. Function signatures have the order be automatic, so when the parameter list is excessively long, it's broken, but when the return type is excessively long, it's broken instead.
Other improvements to the formatting include:
More improvements to the formatter are needed (e.g. respecting comments), but I believe this new formatting algorithm is quite solid, and the remaining changes will mostly be in how the
Contentpassed to the algorithm is generated.I also added a
vine showcommand, which prints a Vine file formatted to the width of the terminal and syntax highlighted. (yes I added syntax highlighting to the formatter. no I'm not sorry.) It also has a--watchmode which reformats the file as the terminal is resized; it's not super useful from an end-user perspective, but it is fun to play with, and is very useful for debugging/testing the formatter.