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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/SKSupport/LineTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import LSPLogging

#if canImport(os)
import os
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ struct ConvertStringConcatenationToStringInterpolation: SyntaxRefactoringProvide
[
ExprSyntax(
StringLiteralExprSyntax(
leadingTrivia: syntax.leadingTrivia,
openingPounds: commonPounds,
openingQuote: .stringQuoteToken(),
segments: segments,
closingQuote: .stringQuoteToken(),
closingPounds: commonPounds
closingPounds: commonPounds,
trailingTrivia: componentsOnly.last?.kind == .stringLiteralExpr ? syntax.trailingTrivia : nil
)
)
]
Expand Down
9 changes: 6 additions & 3 deletions Tests/SourceKitLSPTests/CodeActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,10 @@ final class CodeActionTests: XCTestCase {
func testConvertStringConcatenationToStringInterpolation() async throws {
try await assertCodeActions(
#"""
1️⃣#"["# + 2️⃣key + ": \(3️⃣d) " + 4️⃣value + ##"]"##5️⃣
0️⃣
1️⃣/*leading*/ #"["# + 2️⃣key + ": \(3️⃣d) " + 4️⃣value + ##"]"## /*trailing*/5️⃣
"""#,
markers: ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"],
ranges: [("1️⃣", "2️⃣"), ("3️⃣", "4️⃣"), ("1️⃣", "5️⃣")],
exhaustive: false
) { uri, positions in
Expand All @@ -1022,9 +1024,10 @@ final class CodeActionTests: XCTestCase {
changes: [
uri: [
TextEdit(
range: positions["1️⃣"]..<positions["5️⃣"],
range: positions["0️⃣"]..<positions["5️⃣"],
newText: ###"""
##"[\##(key): \##(d) \##(value)]"##

/*leading*/ ##"[\##(key): \##(d) \##(value)]"## /*trailing*/
"""###
)
]
Expand Down