Skip to content

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

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 25, 2024

rdar://123287930

@ahoppen ahoppen requested a review from bnbarham as a code owner February 25, 2024 17:50
@ahoppen
Copy link
Member Author

ahoppen commented Feb 25, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 26, 2024

swiftlang/swift#71877

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 26, 2024

swiftlang/swift#71877

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Feb 26, 2024

swiftlang/swift#71877

@swift-ci Please test Windows

Comment on lines 588 to 589
var leadingTriviaIndentation: Trivia
var trailingTriviaIndentation: Trivia
Copy link
Contributor

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.

Suggested change
var leadingTriviaIndentation: Trivia
var trailingTriviaIndentation: Trivia
let leadingTriviaIndentation: Trivia
let trailingTriviaIndentation: Trivia

Comment on lines 76 to 79
self.indentationStack = [self.indentationStack.first!]
self.anchorPoints = [:]
self.previousToken = nil
self.stringLiteralNestingLevel = 0
Copy link
Contributor

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.

Suggested change
self.indentationStack = [self.indentationStack.first!]
self.anchorPoints = [:]
self.previousToken = nil
self.stringLiteralNestingLevel = 0
indentationStack = [indentationStack.first!]
anchorPoints = [:]
previousToken = nil
stringLiteralNestingLevel = 0

Copy link
Member Author

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.

Copy link
Contributor

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? 🤔

Copy link
Member Author

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.

@ahoppen ahoppen force-pushed the ahoppen/trailing-trivia-whitespace branch from ad014b0 to d1765f8 Compare February 27, 2024 00:14
@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2024

swiftlang/swift#71877

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 28, 2024

swiftlang/swift#71877

@swift-ci Please test macOS

Comment on lines +72 to +74
/// Clears all stateful data from this `BasicFormat`.
///
/// This needs to be called between multiple `rewrite` calls to a syntax tree.
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Member Author

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.

@ahoppen ahoppen force-pushed the ahoppen/trailing-trivia-whitespace branch from d1765f8 to 48f665c Compare February 29, 2024 18:28
@ahoppen
Copy link
Member Author

ahoppen commented Feb 29, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 29, 2024

swiftlang/swift#71877

@swift-ci Please test

@ahoppen ahoppen merged commit 54887a8 into swiftlang:main Mar 1, 2024
@ahoppen ahoppen deleted the ahoppen/trailing-trivia-whitespace branch March 1, 2024 22:04
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request Mar 2, 2024
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.

3 participants