-
Notifications
You must be signed in to change notification settings - Fork 439
Fix wrong formatting of multiline string literal #1623
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 wrong formatting of multiline string literal #1623
Conversation
e248934
to
e49abe0
Compare
Tests/SwiftParserTest/translated/AvailabilityQueryUnavailabilityTests.swift
Show resolved
Hide resolved
Tests/SwiftParserTest/translated/UnclosedStringInterpolationTests.swift
Outdated
Show resolved
Hide resolved
e49abe0
to
06e701c
Compare
06e701c
to
e021732
Compare
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’m not sure if it changes anything test-wise but since you are adding a trailing newline, that should also be reflected in previousTokenWillEndWithWhitespace
. I.e. the return there should be replaced by the following (slightly refactored to improve readability.
if previousToken.trailingTrivia.endsWithWhitespace {
return true
}
if isMutable(previousToken) && (requiresWhitespace(between: previousToken, and: token) || requiresTrailingNewline(previousToken)) {
return true
}
return false
e375328
to
d84ceb3
Compare
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. This ended up being a pretty small change after all 😆
Unrelated to this PR, I think there’s still an error where we don’t insert the newline after the opening """
:
assertBuildResult(
StringLiteralExprSyntax(openQuote: .multilineStringQuoteToken(), content: "a", closeQuote: .multilineStringQuoteToken()),
#"""
"""
a
"""
"""#
)
Would you like to look into that as well? If you don’t want to look at it straight away, I will file an issue for it.
@swift-ci Please test |
d84ceb3
to
74aa602
Compare
@swift-ci please test |
@swift-ci please test linux |
@swift-ci please test Windows |
c51b0d6
to
fc2e999
Compare
@swift-ci please test |
@swift-ci please test |
I don't understand why it says I haven't generated files. |
fc2e999
to
3fccbe7
Compare
Found the reason. Tried to resolve and update but got those errors kimdevos@dk-kimdevos12-8752 CodeGeneration % swift package resolve
Updating /Users/kimdevos/repository/kimdv/swift-src/swift-syntax
Updated /Users/kimdevos/repository/kimdv/swift-src/swift-syntax (0.47s)
error: could not find a branch named ‘HEAD’ in /Users/kimdevos/repository/kimdv/swift-src/swift-syntax
kimdevos@dk-kimdevos12-8752 CodeGeneration % swift package update
Updating /Users/kimdevos/repository/kimdv/swift-src/swift-syntax
Updated /Users/kimdevos/repository/kimdv/swift-src/swift-syntax (0.17s)
error: could not find a branch named ‘HEAD’ in /Users/kimdevos/repository/kimdv/swift-src/swift-syntax I deleted the Looks a bit like a bug in SPM? |
@swift-ci please test |
@swift-ci please test windows |
I think that’s intentional. Unless you run
I was able to reproduce this as well but then couldn’t reproduce it again by creating a new commit and running |
124adcc
to
6fb0cb9
Compare
758daa8
to
08fecd9
Compare
@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.
Wohooo. Nice. This looks really good now. I only have a few remarks mostly about naming and documentation.
} | ||
if let ancestorsParent = ancestor.parent, childrenSeparatedByNewline(ancestorsParent) { | ||
} else if let second { | ||
if second.requiresLeadingNewline { |
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.
Definitely not part of this PR, but eventually I would like to remove requiresLeadingNewline
from CodeGen altogether and just list the tokens that require a leading newline in this function. Same for childrenSeparatedByNewline
. I don’t think we necessarily need to CodeGen it, it could just be implemented manually in this file.
8b61a40
to
2521ba5
Compare
2521ba5
to
ac5dcb4
Compare
@swift-ci please test |
@swift-ci please test windows |
ac5dcb4
to
6f41221
Compare
@swift-ci please test |
@swift-ci please test windows |
…ltiline-string-literal
…ltiline-string-literal
Fixes #1603
I tried you comment here: #1616 (comment)
But it didn't work for me.
What I figured out what because if it have an open
"""
but not a closing"""
then the formatter will only format on the closing one.It sounds to me that works as intended. Only visit the tokens we fix.