Factor out all leadingTrivia
logic into Format
#645
Merged
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.
This PR moves the entire
leadingTrivia
logic intoFormat
, thereby allowing for a cleaner separation of concerns: Thebuild...
methods inBuildableNodes
/BuildableCollectionNodes
only generate the syntax, theformat._format
methods then deal with indentation.In particular, the
leadingTrivia
parameter that was passed alongsideformat: Format
is no longer needed. Since many test cases, however, rely on this ad-hoc leading trivia generation, I have migrated as many tests as possible to theleadingTrivia
-as-field. For smaller nodes, such as literals, which are heavily sugared through their respective convenience initializers, this would become too verbose, therefore I have removed the unexpected trivia node in those cases. Feel free to discuss this though!Some notes:
@_spi(Testing)
for currently public indentation methods/properties onFormat
will come in a future PR since it depends on Add attributes to VariableDecl convenience initializers #644 and is mostly orthogonal to the changes in this PR.build...
methods is that this becomes complicated for children that may or may not require leading newlines and due to some other complications such as not being able to switch over the parent'sSyntaxEnum
before constructing its syntax (usingSyntaxKind
would have been an option, but would have required us to use the low-level SPI). In general, I think the overloaded_format
methods are the more elegant solution here, also since we don't add a lot of unneeded empty trivias, but I would be curious to hear your thoughts on this!main
on debug builds ofgenerate-swift-syntax-builder
.