-
Notifications
You must be signed in to change notification settings - Fork 440
Fix trivia handling issues in editor placeholder expansion #2511
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
Fix trivia handling issues in editor placeholder expansion #2511
Conversation
@swift-ci Please test |
@swift-ci Please test |
@swift-ci Please test Windows |
1 similar comment
@swift-ci Please test Windows |
var leadingTriviaIndentation: Trivia | ||
var trailingTriviaIndentation: 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.
I believe since you removed default values in these properties we can change them to let
's since they are not mutating anymore.
var leadingTriviaIndentation: Trivia | |
var trailingTriviaIndentation: Trivia | |
let leadingTriviaIndentation: Trivia | |
let trailingTriviaIndentation: Trivia |
self.indentationStack = [self.indentationStack.first!] | ||
self.anchorPoints = [:] | ||
self.previousToken = nil | ||
self.stringLiteralNestingLevel = 0 |
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.
NIT-PICK ALERT!
From what I can see we are not using self
in other places in this class.
self.indentationStack = [self.indentationStack.first!] | |
self.anchorPoints = [:] | |
self.previousToken = nil | |
self.stringLiteralNestingLevel = 0 | |
indentationStack = [indentationStack.first!] | |
anchorPoints = [:] | |
previousToken = nil | |
stringLiteralNestingLevel = 0 |
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, if only we were consistent about using self
or not using self
. But good catch, I removed 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.
Doesn't swift-format has a rule for that? 🤔
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.
No, because knowing whether self
requires semantic knowledge. For example you can’t omit the self
if there’s also a local variable with the same name.
ad014b0
to
d1765f8
Compare
@swift-ci Please test |
@swift-ci Please test |
@swift-ci Please test macOS |
/// Clears all stateful data from this `BasicFormat`. | ||
/// | ||
/// This needs to be called between multiple `rewrite` calls to a syntax tree. |
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.
Could we just override rewrite
and do this in there instead?
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.
rewrite
currently isn’t open
. And I don’t really want to make it open
just for that reason… Thinking about this, I thought about introducing BasicFormat.format(_ node: some SyntaxProtocol)
but that would be the same as SyntaxProtocol.formatted(using: BasicFormat)
. So, maybe we should just make reset
internal and tell people to use SyntaxProtocol.formatted
?
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.
Updated it to make reset
internal again with the intention that you format code by calling SyntaxProtocol.formatted
.
rdar://123287930
d1765f8
to
48f665c
Compare
@swift-ci Please test |
@swift-ci Please test |
rdar://123287930