Skip to content

Add a function to merge trivia from a node into an existing trivia #1478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2023

Conversation

bnbarham
Copy link
Contributor

Generally when a node is removed, we need to add its trivia to an
existing node. Add a small helper function to aid in this case.

@bnbarham bnbarham requested a review from ahoppen as a code owner March 31, 2023 05:26
@bnbarham
Copy link
Contributor Author

@swift-ci please test

Comment on lines +38 to +47
/// Creates a new `Trivia` by appending the provided `TriviaPiece` to the end.
public func appending(_ piece: TriviaPiece) -> Trivia {
var copy = pieces
copy.append(piece)
return Trivia(pieces: copy)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another natural candidate would be appending(_ trivia: Trivia) -> Trivia. I might actually prefer to have a bunch of appending methods instead of overloading +. But that’s not really part of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I too prefer appending, I'm happy to do that here if you want. I generally dislike operator overloading 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so let’s get rid of the + overload now 🗑️

Copy link
Contributor Author

@bnbarham bnbarham Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used... in quite a few places. I'd rather get this in for now, so another PR it is 😅. I've added the other appending and used it in the + implementations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽 Maybe we can deprecate it in a follow-up PR 🤔

@bnbarham
Copy link
Contributor Author

This one actually depends on #1477 so I'll wait to re-run tests until it's in.

The actual `Trivia` definition doesn't need to be generated at all, only
the static funcs and vars. Move it into SwiftSyntax proper.
@bnbarham bnbarham force-pushed the merge-trivia branch 2 times, most recently from 4808ee2 to c2557f9 Compare April 5, 2023 03:09
@@ -227,7 +227,12 @@ func validateLayout(layout: RawSyntaxBuffer, as kind: SyntaxKind) {
case .accessPathComponent:
assert(layout.count == 5)
assertNoError(kind, 0, verify(layout[0], as: RawUnexpectedNodesSyntax?.self))
assertNoError(kind, 1, verify(layout[1], as: RawTokenSyntax.self, tokenChoices: [.tokenKind(.identifier)]))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we didn't regenerate in aea4442?

@bnbarham
Copy link
Contributor Author

bnbarham commented Apr 5, 2023

@swift-ci please test

@bnbarham
Copy link
Contributor Author

bnbarham commented Apr 5, 2023

@swift-ci please test

@bnbarham bnbarham force-pushed the merge-trivia branch 2 times, most recently from f83fe74 to f032eee Compare April 5, 2023 19:57
@bnbarham
Copy link
Contributor Author

bnbarham commented Apr 5, 2023

@swift-ci please test

@bnbarham
Copy link
Contributor Author

bnbarham commented Apr 5, 2023

@swift-ci please test

Generally when a node is removed, we need to add its trivia to an
existing node. Add a small helper function to aid in this case.
@bnbarham
Copy link
Contributor Author

bnbarham commented Apr 6, 2023

@swift-ci please test

@bnbarham
Copy link
Contributor Author

bnbarham commented Apr 7, 2023

@swift-ci please test Windows platform

@bnbarham bnbarham merged commit b97b41f into swiftlang:main Apr 7, 2023
@bnbarham bnbarham deleted the merge-trivia branch April 7, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants