mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
fixed the issue that leading and trailing trivia are lost after string interpolation conversion
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import LSPLogging
|
||||
|
||||
#if canImport(os)
|
||||
import os
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
@@ -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
|
||||
@@ -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*/
|
||||
"""###
|
||||
)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user