Workaround new trivia behavior in SwiftSyntax. #434
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.
As of swiftlang/swift-syntax#985, the parser treats all trivia following a token up to the next line break as trailing trivia, including comments. This is a change from the former logic, which treated such comments as leading trivia of the following token.
A great deal of the logic in swift-format was written in terms of that behavior, and attempts to rewrite it to use the new behavior instead have been difficult to get right in all cases. In the interest of expediency, I'm merging this workaround that shifts the trivia around to restore the old tree that we expected.
This shouldn't be considered a long-term fix; we should eventually fix the misbehavior with the new layout and drop the extra mutation.
This PR also includes some other fixes for API changes in SwiftSyntax:
visit(TokenSyntax)
now returnsTokenSyntax
MacroExpansionExprSyntax
instead ofMacroExpansionDeclSyntax