-
Notifications
You must be signed in to change notification settings - Fork 439
Improve implementation of BasicFormat (yet again) #1558
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
e759209
to
23d2072
Compare
@swift-ci Please test |
/// This is used as a reference-point to indent user-indented code. | ||
var anchorPoints: [TokenSyntax: Trivia] = [:] | ||
|
||
public init(indentationIncrement: Trivia = .spaces(4), initialIndentation: Trivia = []) { |
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.
Not sure if I like the default value is []
. I think it's a but hard to understand maybe for new developers.
But on the the other hand I cannot find any other name than .zero
, .none
, .empty
. And I'm not convinced they fit either.
Specially because we on line 36 add and array in an array.
That is the same if we did initialIndentation: Trivia = .space(2)
etc.
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.
We used to have Trivia.zero
but IIRC @bnbarham removed it because it was redundant with the empty array. Do you have strong options on whether we should add it (or .empty
) back in again?
In line 36: Well, indentationStack
is an array of trivia again. And arrays of arrays aren’t that uncommon, so I think that should be fine…
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.
This is looking really great! 😍
Huge improvement IMO.
Just added some comments for discussion/questions I have.
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.
Nice, seems to work pretty well. Might be good to add a stripIndentation
so the BasicFormat indentation can be preferred even if the string interpolation is being used with whatever indentation an author had there.
CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/TriviaPiecesFile.swift
Outdated
Show resolved
Hide resolved
192a551
to
20e2ebe
Compare
This re-writes the implementation of BasicFormat once again to better handle user-indented code. Co-authored-by: Ben Barham <[email protected]>
This mostly improves performance by calling `previousToken`, `nextToken`, and `firstToken` less often.
20e2ebe
to
46aab36
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
684d268
to
46aab36
Compare
@swift-ci Please test |
@swift-ci Please test Linux |
46aab36
to
2e4761e
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
This re-writes the implementation of BasicFormat once again to better handle user-indented code.