Skip to content

BasicFormat should not format unexpected nodes #1759

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 1 commit into from
Jun 22, 2023

Conversation

bnbarham
Copy link
Contributor

@bnbarham bnbarham commented Jun 9, 2023

BasicFormat depends on the parent layout nodes to determine formatting in some cases, so it doesn't make sense to visit unexpected nodes.

Also fix up SyntaxRewriter to take a viewMode, since as it was BasicFormat was actually visiting missing nodes, which also doesn't make much sense.

Resolves rdar://110463876.

@bnbarham bnbarham requested a review from rintaro June 9, 2023 22:17
@bnbarham
Copy link
Contributor Author

bnbarham commented Jun 9, 2023

@swift-ci please test

@bnbarham
Copy link
Contributor Author

swiftlang/swift#66569

@swift-ci please test

@bnbarham
Copy link
Contributor Author

swiftlang/swift#66569

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test

@@ -475,6 +475,7 @@ extension OperatorTable {
) {
self.opPrecedence = opPrecedence
self.errorHandler = errorHandler
super.init(viewMode: .sourceAccurate)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really only want to fold source accurate nodes here? I would think of sequence folding as a semantic operation and thus think that it might be better off folding the fixed up tree.

Copy link
Contributor Author

@bnbarham bnbarham Jun 16, 2023

Choose a reason for hiding this comment

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

Ideally we wouldn't be folding at all if there's any errors 😅. Let's say there's a bunch of unexpected nodes, do we expect folding to remove them all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, except we won't remove them (thanks @rintaro). So I suppose I don't really have a preference here. I can do fixed up 🤷

@bnbarham
Copy link
Contributor Author

swift-format also uses visit(Syntax). I'm going to move dropping that function out of this PR. It's unrelated to not formatting unexpected nodes.

@bnbarham bnbarham force-pushed the macro-formatting branch 3 times, most recently from bae6ff8 to 2c46280 Compare June 17, 2023 01:45
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test Windows platform

`BasicFormat` depends on the parent layout nodes to determine formatting
in some cases, so it doesn't make sense to visit unexpected nodes.

Also fix up `SyntaxRewriter` to take a `viewMode`, since as it was
`BasicFormat` was actually visiting `missing` nodes, which also doesn't
make much sense.

Resolves rdar://110463876.
@bnbarham
Copy link
Contributor Author

@swift-ci please test

@bnbarham
Copy link
Contributor Author

@swift-ci please test Windows platform

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