Skip to content

Fix for trivia not preserved after string interpolation conversion #1575

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

AppAppWorks
Copy link
Contributor

@AppAppWorks AppAppWorks commented Jul 18, 2024

fix an issue in #1551

My bad, I should've tested the code action more thoroughly. The leading trivia of the source SequenceExprSyntax is not carried over to the new string literal, resulting in this:

<code block A>
"" + value + ""
<code block B>

->

<code block A>"\(value)"
<code block B>

This fix will preserve the leading trivia, i.e.

<code block A>
"\(value)"
<code block B>

@AppAppWorks AppAppWorks requested a review from ahoppen as a code owner July 18, 2024 07:53
@ahoppen
Copy link
Member

ahoppen commented Jul 18, 2024

How was // code block A preserved before this change if the leading trivia of the code block weren’t preserved? Or did you mean for // code block A to be a statement?

Should we also retain the trailing trivia from syntax in the same way?

@AppAppWorks
Copy link
Contributor Author

Yeah, // code block A was meant for a statement instead of a comment, I've changed that in the description above.

AFAIK, string literals don't have trailing trivia, and trailing trivia of any non-string-literal component will be converted and moved into the string interpolation, so the trailing trivia of syntax has been preserved in this way.

@ahoppen
Copy link
Member

ahoppen commented Jul 18, 2024

What about "a" + b + "c" / * some comment */? In that case /* some comment */ should be trailing trivia for the ".

@AppAppWorks AppAppWorks force-pushed the fix-leading-trivia-convert-string-concatenation-to-string-interpolation branch from 114a2a8 to e040e76 Compare July 18, 2024 23:13
@AppAppWorks AppAppWorks changed the title Fix for leading trivia not preserved after string interpolation conversion Fix for trivia not preserved after string interpolation conversion Jul 18, 2024
@ahoppen
Copy link
Member

ahoppen commented Jul 19, 2024

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Jul 19, 2024

@swift-ci Please test Windows

newText: ###"""
##"[\##(key): \##(d) \##(value)]"##

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line has trailing whitespace. Could you run swift-format on your changes? https://github.com/swiftlang/sourcekit-lsp/blob/main/CONTRIBUTING.md#formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please test again.

@AppAppWorks AppAppWorks force-pushed the fix-leading-trivia-convert-string-concatenation-to-string-interpolation branch from e040e76 to db3867b Compare July 20, 2024 23:45
@ahoppen
Copy link
Member

ahoppen commented Jul 22, 2024

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge July 22, 2024 16:48
@ahoppen
Copy link
Member

ahoppen commented Jul 22, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 82e54ef into swiftlang:main Jul 22, 2024
3 checks passed
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.

2 participants