@@ -22,22 +22,34 @@ struct GeneratedInterfaceInfo {
22
22
23
23
extension SwiftLanguageService {
24
24
public func openGeneratedInterface(
25
- _ request: OpenGeneratedInterfaceRequest
25
+ document: DocumentURI ,
26
+ moduleName: String ,
27
+ groupName: String ? ,
28
+ symbolUSR symbol: String ?
26
29
) async throws -> GeneratedInterfaceDetails ? {
27
- let name = request. name
28
- let symbol = request. symbolUSR
30
+ // Name of interface module name with group names appended
31
+ let name =
32
+ if let groupName {
33
+ " \( moduleName) . \( groupName. replacing ( " / " , with: " . " ) ) "
34
+ } else {
35
+ moduleName
36
+ }
29
37
let interfaceFilePath = self . generatedInterfacesPath. appendingPathComponent ( " \( name) .swiftinterface " )
30
38
let interfaceDocURI = DocumentURI ( interfaceFilePath)
31
39
// has interface already been generated
32
40
if let snapshot = try ? self . documentManager. latestSnapshot ( interfaceDocURI) {
33
41
return await self . generatedInterfaceDetails (
34
- request: request,
35
42
uri: interfaceDocURI,
36
43
snapshot: snapshot,
37
44
symbol: symbol
38
45
)
39
46
} else {
40
- let interfaceInfo = try await self . generatedInterfaceInfo ( request: request, interfaceURI: interfaceDocURI)
47
+ let interfaceInfo = try await self . generatedInterfaceInfo (
48
+ document: document,
49
+ moduleName: moduleName,
50
+ groupName: groupName,
51
+ interfaceURI: interfaceDocURI
52
+ )
41
53
try interfaceInfo. contents. write ( to: interfaceFilePath, atomically: true , encoding: String . Encoding. utf8)
42
54
let snapshot = DocumentSnapshot (
43
55
uri: interfaceDocURI,
@@ -46,7 +58,6 @@ extension SwiftLanguageService {
46
58
lineTable: LineTable ( interfaceInfo. contents)
47
59
)
48
60
let result = await self . generatedInterfaceDetails (
49
- request: request,
50
61
uri: interfaceDocURI,
51
62
snapshot: snapshot,
52
63
symbol: symbol
@@ -61,31 +72,34 @@ extension SwiftLanguageService {
61
72
/// Open the Swift interface for a module.
62
73
///
63
74
/// - Parameters:
64
- /// - request: The OpenGeneratedInterfaceRequest.
75
+ /// - document: The document whose compiler arguments should be used to generate the interface.
76
+ /// - moduleName: The module to generate an index for.
77
+ /// - groupName: The module group name.
65
78
/// - interfaceURI: The file where the generated interface should be written.
66
79
///
67
80
/// - Important: This opens a document with name `interfaceURI.pseudoPath` in sourcekitd. The caller is responsible
68
81
/// for ensuring that the document will eventually get closed in sourcekitd again.
69
82
private func generatedInterfaceInfo(
70
- request: OpenGeneratedInterfaceRequest ,
83
+ document: DocumentURI ,
84
+ moduleName: String ,
85
+ groupName: String ? ,
71
86
interfaceURI: DocumentURI
72
87
) async throws -> GeneratedInterfaceInfo {
73
88
let keys = self . keys
74
89
let skreq = sourcekitd. dictionary ( [
75
90
keys. request: requests. editorOpenInterface,
76
- keys. moduleName: request . moduleName,
77
- keys. groupName: request . groupName,
91
+ keys. moduleName: moduleName,
92
+ keys. groupName: groupName,
78
93
keys. name: interfaceURI. pseudoPath,
79
94
keys. synthesizedExtension: 1 ,
80
- keys. compilerArgs: await self . buildSettings ( for: request . textDocument . uri ) ? . compilerArgs as [ SKDRequestValue ] ? ,
95
+ keys. compilerArgs: await self . buildSettings ( for: document ) ? . compilerArgs as [ SKDRequestValue ] ? ,
81
96
] )
82
97
83
98
let dict = try await self . sourcekitd. send ( skreq, fileContents: nil )
84
99
return GeneratedInterfaceInfo ( contents: dict [ keys. sourceText] ?? " " )
85
100
}
86
101
87
102
private func generatedInterfaceDetails(
88
- request: OpenGeneratedInterfaceRequest ,
89
103
uri: DocumentURI ,
90
104
snapshot: DocumentSnapshot ,
91
105
symbol: String ?
0 commit comments