Skip to content

Commit 403c6eb

Browse files
committed
Support creation of `InProcessSourceKitLSPClient with a list of Xcode toolchains
1 parent 03da7e9 commit 403c6eb

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Sources/Diagnose/IndexCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ package struct IndexCommand: AsyncParsableCommand {
113113

114114
let messageHandler = IndexLogMessageHandler()
115115
let inProcessClient = try await InProcessSourceKitLSPClient(
116-
toolchainPath: installPath,
116+
toolchainRegistry: ToolchainRegistry(installPath: installPath),
117117
options: options,
118118
workspaceFolders: [WorkspaceFolder(uri: DocumentURI(URL(fileURLWithPath: project)))],
119119
messageHandler: messageHandler

Sources/InProcessClient/InProcessSourceKitLSPClient.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ public import LanguageServerProtocol
1616
import LanguageServerProtocolExtensions
1717
import SwiftExtensions
1818
import TSCExtensions
19-
import ToolchainRegistry
2019

2120
import struct TSCBasic.AbsolutePath
2221

2322
#if compiler(>=6)
2423
package import SKOptions
2524
package import SourceKitLSP
25+
package import ToolchainRegistry
2626
#else
2727
import SKOptions
2828
import SourceKitLSP
29+
import ToolchainRegistry
2930
#endif
3031

3132
/// Launches a `SourceKitLSPServer` in-process and allows sending messages to it.
@@ -41,7 +42,7 @@ public final class InProcessSourceKitLSPClient: Sendable {
4142
messageHandler: any MessageHandler
4243
) async throws {
4344
try await self.init(
44-
toolchainPath: toolchainPath,
45+
toolchainRegistry: ToolchainRegistry(installPath: toolchainPath),
4546
options: SourceKitLSPOptions(),
4647
capabilities: capabilities,
4748
workspaceFolders: workspaceFolders,
@@ -53,7 +54,7 @@ public final class InProcessSourceKitLSPClient: Sendable {
5354
///
5455
/// `messageHandler` handles notifications and requests sent from the SourceKit-LSP server to the client.
5556
package init(
56-
toolchainPath: URL?,
57+
toolchainRegistry: ToolchainRegistry,
5758
options: SourceKitLSPOptions = SourceKitLSPOptions(),
5859
hooks: Hooks = Hooks(),
5960
capabilities: ClientCapabilities = ClientCapabilities(),
@@ -63,7 +64,7 @@ public final class InProcessSourceKitLSPClient: Sendable {
6364
let serverToClientConnection = LocalConnection(receiverName: "client")
6465
self.server = SourceKitLSPServer(
6566
client: serverToClientConnection,
66-
toolchainRegistry: ToolchainRegistry(installPath: toolchainPath),
67+
toolchainRegistry: toolchainRegistry,
6768
options: options,
6869
hooks: hooks,
6970
onExit: {

Sources/ToolchainRegistry/ToolchainRegistry.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ package final actor ToolchainRegistry {
145145
}
146146
}
147147

148+
package init(xcodeToolchains toolchainPaths: [URL]) {
149+
let toolchainsAndReasons: [(toolchain: Toolchain, reason: ToolchainRegisterReason)] = toolchainPaths.compactMap {
150+
path in
151+
guard let toolchain = Toolchain(path) else {
152+
return nil
153+
}
154+
return (toolchain, .xcode)
155+
}
156+
self.init(toolchainsAndReasons: toolchainsAndReasons, darwinToolchainOverride: nil)
157+
}
158+
148159
/// A toolchain registry used for testing that scans for toolchains based on environment variables and Xcode
149160
/// installations but not next to the `sourcekit-lsp` binary because there is no `sourcekit-lsp` binary during
150161
/// testing.

0 commit comments

Comments
 (0)