-
Notifications
You must be signed in to change notification settings - Fork 441
Add an 'indented' method to SyntaxProtocol #2843
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
Conversation
@swift-ci please test |
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.
Sorry for taking sooooooo long to get back to this. We already have Indenter
in SwiftSyntaxBuilder
, which serves the same purpose. I don’t think that Indenter
was ever intended to be public API, but now it’s out there.
I think your API is the nicer one (doesn’t expose a SyntaxRewriter
) but I think it would be good to unify these two implementations. Could you:
- Mark the
Indenter
class inSwiftSyntaxBuilder
as deprecated? - Migrate all uses of
Indenter
inside swift-syntax to your indentation method? - Add release note entries for the deprecation of the
Indenter
and the introduction of the newindented
method?
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Why might the
|
A |
It’s a local generic type (which must be shadowing the real |
You need to add |
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.
Thanks you for coming back to this after I took a while, @j-f1. Looks good to me, just a few minor comments.
self.shouldIndent = indentFirstLine | ||
} | ||
|
||
private func indentIfNeeded() -> [TriviaPiece] { |
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.
Also, I would call it indentationIfNeeded
because indentIfNeeded
sounds like an action that’s actively indenting something but this just returns the indentation.
Same for indentAfterNewlines
.
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.
indentAfterNewlines
does actually perform the indentation (and returns the indented string) but I’ve renamed indentIfNeeded
.
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
@swift-ci please test |
@swift-ci please test Windows |
This method allows for easily indenting a node tree without needing to manually find where to place the new trivia.
I also chose not to implement a version that automatically detects an amount to indent by using
BasicFormat.inferIndentation
since that would probably produce better results if called higher up in the tree, and the user of this API can more easily cache that calculated indentation amount and pass it toindent
multiple times as needed.