11
11
//===----------------------------------------------------------------------===//
12
12
13
13
import SKLogging
14
- @_spi ( SourceKitLSP ) import SwiftRefactor
14
+ @_spi ( RawSyntax ) import SwiftSyntax
15
15
16
16
func rewriteSourceKitPlaceholders( in string: String , clientSupportsSnippets: Bool ) -> String {
17
17
var result = string
@@ -22,7 +22,7 @@ func rewriteSourceKitPlaceholders(in string: String, clientSupportsSnippets: Boo
22
22
return string
23
23
}
24
24
let rawPlaceholder = String ( result [ start. lowerBound..< end. upperBound] )
25
- guard let displayName = EditorPlaceholderData ( text : rawPlaceholder) ? . nameForSnippet else {
25
+ guard let displayName = nameForSnippet ( rawPlaceholder) else {
26
26
logger. fault ( " Failed to decode placeholder \( rawPlaceholder) in \( string) " )
27
27
return string
28
28
}
@@ -33,15 +33,14 @@ func rewriteSourceKitPlaceholders(in string: String, clientSupportsSnippets: Boo
33
33
return result
34
34
}
35
35
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
45
43
}
44
+ return String ( syntaxText: data. typeForExpansionText ?? data. displayText)
46
45
}
47
46
}
0 commit comments