Skip to content

Commit 0da1d40

Browse files
committed
Move module name split into OpenInterfaceRequest
Use group names when running open interface request
1 parent bbc4eee commit 0da1d40

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

Sources/LanguageServerProtocol/Requests/OpenInterfaceRequest.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,35 @@ public struct OpenInterfaceRequest: TextDocumentRequest, Hashable {
2020
public var textDocument: TextDocumentIdentifier
2121

2222
/// The module to generate an index for.
23-
public var name: String
23+
public var moduleName: String
24+
25+
/// The module group name.
26+
public var groupNames: [String]
2427

2528
/// The symbol to search for in the generated module interface.
2629
public var symbol: String?
2730

2831
public init(textDocument: TextDocumentIdentifier, name: String, symbol: String?) {
2932
self.textDocument = textDocument
30-
self.name = name
3133
self.symbol = symbol
34+
// Stdlib Swift modules are all in the "Swift" module, but their symbols return a module name `Swift.***`.
35+
let splitName = name.split(separator: ".")
36+
if splitName.count == 1 {
37+
self.moduleName = name
38+
self.groupNames = []
39+
} else {
40+
self.moduleName = String(splitName[0])
41+
self.groupNames = [String.SubSequence](splitName.dropFirst()).map { String($0)}
42+
}
43+
}
44+
45+
/// Name of interface module name with group names appended
46+
public var name: String {
47+
if groupNames.count > 0 {
48+
return "\(self.moduleName).\(self.groupNames.joined(separator: "."))"
49+
} else {
50+
return self.moduleName
51+
}
3252
}
3353
}
3454

Sources/SourceKitD/sourcekitd_uids.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public struct sourcekitd_keys {
4040
public let expression_type_list: sourcekitd_uid_t
4141
public let filepath: sourcekitd_uid_t
4242
public let fixits: sourcekitd_uid_t
43+
public let groupname: sourcekitd_uid_t
4344
public let id: sourcekitd_uid_t
4445
public let is_system: sourcekitd_uid_t
4546
public let kind: sourcekitd_uid_t
@@ -115,6 +116,7 @@ public struct sourcekitd_keys {
115116
expression_type_list = api.uid_get_from_cstr("key.expression_type_list")!
116117
filepath = api.uid_get_from_cstr("key.filepath")!
117118
fixits = api.uid_get_from_cstr("key.fixits")!
119+
groupname = api.uid_get_from_cstr("key.groupname")!
118120
id = api.uid_get_from_cstr("key.id")!
119121
is_system = api.uid_get_from_cstr("key.is_system")!
120122
kind = api.uid_get_from_cstr("key.kind")!

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,6 @@ extension SourceKitServer {
13601360
symbol: String?,
13611361
languageService: ToolchainLanguageServer
13621362
) {
1363-
var moduleName = moduleName
1364-
// Stdlib Swift modules are all in the "Swift" module, but their symbols return a module name `Swift.***`.
1365-
if moduleName.hasPrefix("Swift.") {
1366-
moduleName = "Swift"
1367-
}
13681363
let openInterface = OpenInterfaceRequest(textDocument: req.params.textDocument, name: moduleName, symbol: symbol)
13691364
let request = Request(openInterface, id: req.id, clientID: ObjectIdentifier(self),
13701365
cancellation: req.cancellationToken, reply: { (result: Result<OpenInterfaceRequest.Response, ResponseError>) in

Sources/SourceKitLSP/Swift/OpenInterface.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ struct FindUSRInfo {
2727
extension SwiftLanguageServer {
2828
public func openInterface(_ request: LanguageServerProtocol.Request<LanguageServerProtocol.OpenInterfaceRequest>) {
2929
let uri = request.params.textDocument.uri
30-
let moduleName = request.params.name
30+
let moduleName = request.params.moduleName
31+
let name = request.params.name
3132
let symbol = request.params.symbol
3233
self.queue.async {
33-
let interfaceFilePath = self.generatedInterfacesPath.appendingPathComponent("\(moduleName).swiftinterface")
34+
let interfaceFilePath = self.generatedInterfacesPath.appendingPathComponent("\(name).swiftinterface")
3435
let interfaceDocURI = DocumentURI(interfaceFilePath)
3536
// has interface already been generated
3637
if let snapshot = self.documentManager.latestSnapshot(interfaceDocURI) {
@@ -75,6 +76,9 @@ extension SwiftLanguageServer {
7576
let skreq = SKDRequestDictionary(sourcekitd: sourcekitd)
7677
skreq[keys.request] = requests.editor_open_interface
7778
skreq[keys.modulename] = name
79+
if request.params.groupNames.count > 0 {
80+
skreq[keys.groupname] = request.params.groupNames
81+
}
7882
skreq[keys.name] = interfaceURI.pseudoPath
7983
skreq[keys.synthesizedextensions] = 1
8084
if let compileCommand = self.commandsByFile[uri] {

0 commit comments

Comments
 (0)