Change trivia attribution rule to make comments trailing trivia unless separated by a newline#985
Merged
Conversation
…s separated by a newline This changes the trivia attribution rule in the new parser to consider all trivia up to the next newline as trailing trivia. Previously, comments were always considered trailing trivia. This was discussed last year in https://forums.swift.org/t/changing-comment-trivia-attribution-from-trailing-trivia-to-leading-trivia/50773. My idea is that right now is probably one of the best times to change this because switching from the old to the new parser is an active source change for all clients. Resolves rdar://68234477 Resolves rdar://95639215 Fixes swiftlang#438
f479a9e to
60c7037
Compare
Member
Author
|
@swift-ci Please test |
CodaFi
approved these changes
Oct 20, 2022
Contributor
CodaFi
left a comment
There was a problem hiding this comment.
We met to discuss the implications of this change and settled on accepting it. The forum thread contains a number of oddities that these rules still don't quite handle as well as one would hope, but the balance between "smarter" trivia attribution and an efficient trivia lexing scheme struck by this solution is better than the status quo in enough places that it's worth it.
This is also a behavior change that swiftlint and swift-format may have to adapt to.
Contributor
allevato
added a commit
to allevato/swift-format
that referenced
this pull request
Oct 21, 2022
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.
jpsim
added a commit
to realm/SwiftLint
that referenced
this pull request
Oct 23, 2022
This has changes to how comments are associated to nodes. See swiftlang/swift-syntax#985
jpsim
added a commit
to realm/SwiftLint
that referenced
this pull request
Oct 23, 2022
This has changes to how comments are associated to nodes. See swiftlang/swift-syntax#985
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.
This changes the trivia attribution rule in the new parser to consider all trivia up to the next newline as trailing trivia. Previously, comments were always considered trailing trivia.
This was discussed last year in https://forums.swift.org/t/changing-comment-trivia-attribution-from-trailing-trivia-to-leading-trivia/50773.
My idea is that right now is probably one of the best times to change this because switching from the old to the new parser is an active source change for all clients.
Resolves rdar://68234477
Resolves rdar://95639215
Fixes #438
CC @allevato @jpsim