1111//===----------------------------------------------------------------------===//
1212
1313import SKLogging
14- @_spi ( SourceKitLSP ) import SwiftRefactor
14+ @_spi ( RawSyntax ) import SwiftSyntax
1515
1616func 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