-
Notifications
You must be signed in to change notification settings - Fork 440
Fix the indentation for nodes that have a parent node #1791
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the formatter takes a node that has a parent node, I think the initial node should be treated as starting a new line, even if it has a parent node, in order to accurately detect anchor points for indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, very nice find. I was not expecting the issue in this area.
This raises a more fundamental question: What does it even mean to format a
CodeBlockSyntax
item standalone while it still has a parent that’s aFunctionDeclSyntax
? I’m not sure if there really is a correct answer so maybe callingformatted
should detach the syntax node from the tree, in which case we can always assume that we are formatting an entire tree and not just a subtree. What do you think?CC @bnbarham: Do you have any opinions on my thoughts above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, @bnbarham and I talked about this a little bit and I thought about this a little bit more and I think that your approach of setting the anchor point is the right one.
Another test case that I would like to add is the following. Ideally, we would indent the opening
{
by four spaces as well (as inferred from the indentation offunc
, similar to what we do in https://github.com/apple/swift-syntax/pull/1698/files#diff-32042eea35aac988fe01a592484fb9cbbff328267babb16f5eb8af29f8f9c288R64-R77).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your consideration! I agree with you and have included your test case for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thank you. Do you want to work on adding 4 spaces in front of
{
? If not, I’ll file an issue for it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I'd love to work on it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s great. I’m looking forward to your PR.