Skip to content

Commit 5802aad

Browse files
authored
Merge pull request swiftlang#1746 from rintaro/raw-editor-placeholder
Update for EditorPlaceholder SPI changes in swift-syntax
2 parents 741f1e5 + 7add264 commit 5802aad

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Sources/SourceKitLSP/Swift/RewriteSourceKitPlaceholders.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import SKLogging
14-
@_spi(SourceKitLSP) import SwiftRefactor
14+
@_spi(RawSyntax) import SwiftSyntax
1515

1616
func rewriteSourceKitPlaceholders(in string: String, clientSupportsSnippets: Bool) -> String {
1717
var result = string
@@ -22,7 +22,7 @@ func rewriteSourceKitPlaceholders(in string: String, clientSupportsSnippets: Boo
2222
return string
2323
}
2424
let rawPlaceholder = String(result[start.lowerBound..<end.upperBound])
25-
guard let displayName = EditorPlaceholderData(text: rawPlaceholder)?.nameForSnippet else {
25+
guard let displayName = nameForSnippet(rawPlaceholder) else {
2626
logger.fault("Failed to decode placeholder \(rawPlaceholder) in \(string)")
2727
return string
2828
}
@@ -33,15 +33,14 @@ func rewriteSourceKitPlaceholders(in string: String, clientSupportsSnippets: Boo
3333
return result
3434
}
3535

36-
fileprivate extension EditorPlaceholderData {
37-
var nameForSnippet: Substring {
38-
switch self {
39-
case .basic(text: let text): return text
40-
case .typed(text: let text, type: _): return text
41-
#if RESILIENT_LIBRARIES
42-
@unknown default:
43-
fatalError("Unknown case")
44-
#endif
36+
/// Parse a SourceKit placeholder and extract the display name suitable for a
37+
/// LSP snippet.
38+
fileprivate func nameForSnippet(_ text: String) -> String? {
39+
var text = text
40+
return text.withSyntaxText {
41+
guard let data = RawEditorPlaceholderData(syntaxText: $0) else {
42+
return nil
4543
}
44+
return String(syntaxText: data.typeForExpansionText ?? data.displayText)
4645
}
4746
}

0 commit comments

Comments
 (0)