Skip to content

Commit 0fbb646

Browse files
committed
Make BuildSystemKind a struct and rename to BuildSystemSpec
1 parent c1e090e commit 0fbb646

File tree

8 files changed

+72
-63
lines changed

8 files changed

+72
-63
lines changed

Sources/BuildSystemIntegration/BuildSystemManager.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private enum BuildSystemAdapter {
132132
}
133133
}
134134

135-
private extension BuildSystemKind {
135+
private extension BuildSystemSpec {
136136
private static func createBuiltInBuildSystemAdapter(
137137
projectRoot: AbsolutePath,
138138
messagesToSourceKitLSPHandler: any MessageHandler,
@@ -172,8 +172,8 @@ private extension BuildSystemKind {
172172
buildSystemTestHooks testHooks: BuildSystemTestHooks,
173173
messagesToSourceKitLSPHandler: any MessageHandler
174174
) async -> BuildSystemAdapter? {
175-
switch self {
176-
case .buildServer(projectRoot: let projectRoot):
175+
switch self.kind {
176+
case .buildServer:
177177
let buildSystem = await orLog("Creating external build system") {
178178
try await ExternalBuildSystemAdapter(
179179
projectRoot: projectRoot,
@@ -186,7 +186,7 @@ private extension BuildSystemKind {
186186
}
187187
logger.log("Created external build server at \(projectRoot.pathString)")
188188
return .external(buildSystem)
189-
case .compilationDatabase(projectRoot: let projectRoot):
189+
case .compilationDatabase:
190190
return await Self.createBuiltInBuildSystemAdapter(
191191
projectRoot: projectRoot,
192192
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
@@ -200,7 +200,7 @@ private extension BuildSystemKind {
200200
connectionToSourceKitLSP: connectionToSourceKitLSP
201201
)
202202
}
203-
case .swiftPM(projectRoot: let projectRoot):
203+
case .swiftPM:
204204
return await Self.createBuiltInBuildSystemAdapter(
205205
projectRoot: projectRoot,
206206
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
@@ -214,7 +214,7 @@ private extension BuildSystemKind {
214214
testHooks: testHooks.swiftPMTestHooks
215215
)
216216
}
217-
case .testBuildSystem(projectRoot: let projectRoot):
217+
case .testBuildSystem:
218218
return await Self.createBuiltInBuildSystemAdapter(
219219
projectRoot: projectRoot,
220220
messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
@@ -349,7 +349,7 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
349349
}
350350

351351
package init(
352-
buildSystemKind: BuildSystemKind?,
352+
buildSystemSpec: BuildSystemSpec?,
353353
toolchainRegistry: ToolchainRegistry,
354354
options: SourceKitLSPOptions,
355355
connectionToClient: BuildSystemManagerConnectionToClient,
@@ -358,8 +358,8 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
358358
self.toolchainRegistry = toolchainRegistry
359359
self.options = options
360360
self.connectionToClient = connectionToClient
361-
self.projectRoot = buildSystemKind?.projectRoot
362-
self.buildSystemAdapter = await buildSystemKind?.createBuildSystemAdapter(
361+
self.projectRoot = buildSystemSpec?.projectRoot
362+
self.buildSystemAdapter = await buildSystemSpec?.createBuildSystemAdapter(
363363
toolchainRegistry: toolchainRegistry,
364364
options: options,
365365
buildSystemTestHooks: buildSystemTestHooks,
@@ -388,8 +388,8 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
388388
guard let buildSystemAdapter else {
389389
return nil
390390
}
391-
guard let buildSystemKind else {
392-
logger.fault("If we have a connectionToBuildSystem, we must have had a buildSystemKind")
391+
guard let buildSystemSpec else {
392+
logger.fault("If we have a connectionToBuildSystem, we must have had a buildSystemSpec")
393393
return nil
394394
}
395395
let initializeResponse = await orLog("Initializing build system") {
@@ -398,7 +398,7 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
398398
displayName: "SourceKit-LSP",
399399
version: "",
400400
bspVersion: "2.2.0",
401-
rootUri: URI(buildSystemKind.projectRoot.asURL),
401+
rootUri: URI(buildSystemSpec.projectRoot.asURL),
402402
capabilities: BuildClientCapabilities(languageIds: [.c, .cpp, .objective_c, .objective_cpp, .swift])
403403
)
404404
)
@@ -411,7 +411,7 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
411411
// the build server.
412412
logger.log("Launched a legacy BSP server. Using push-based build settings model.")
413413
let legacyBuildServer = await LegacyBuildServerBuildSystem(
414-
projectRoot: buildSystemKind.projectRoot,
414+
projectRoot: buildSystemSpec.projectRoot,
415415
initializationData: initializeResponse,
416416
externalBuildSystemAdapter
417417
)

Sources/BuildSystemIntegration/BuiltInBuildSystemAdapter.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@ import struct TSCBasic.AbsolutePath
2727
import struct TSCBasic.RelativePath
2828
#endif
2929

30-
package enum BuildSystemKind {
31-
case buildServer(projectRoot: AbsolutePath)
32-
case compilationDatabase(projectRoot: AbsolutePath)
33-
case swiftPM(projectRoot: AbsolutePath)
34-
case testBuildSystem(projectRoot: AbsolutePath)
35-
36-
package var projectRoot: AbsolutePath {
37-
switch self {
38-
case .buildServer(let projectRoot): return projectRoot
39-
case .compilationDatabase(let projectRoot): return projectRoot
40-
case .swiftPM(let projectRoot): return projectRoot
41-
case .testBuildSystem(let projectRoot): return projectRoot
42-
}
30+
/// The details necessary to create a `BuildSystemAdapter`.
31+
package struct BuildSystemSpec {
32+
package enum Kind {
33+
case buildServer
34+
case compilationDatabase
35+
case swiftPM
36+
case testBuildSystem
37+
}
38+
39+
package var kind: Kind
40+
41+
package var projectRoot: AbsolutePath
42+
43+
package init(kind: BuildSystemSpec.Kind, projectRoot: AbsolutePath) {
44+
self.kind = kind
45+
self.projectRoot = projectRoot
4346
}
4447
}
4548

Sources/BuildSystemIntegration/DetermineBuildSystem.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import struct TSCBasic.AbsolutePath
3535
package func determineBuildSystem(
3636
forWorkspaceFolder workspaceFolder: DocumentURI,
3737
options: SourceKitLSPOptions
38-
) -> BuildSystemKind? {
38+
) -> BuildSystemSpec? {
3939
var buildSystemPreference: [WorkspaceType] = [
4040
.buildServer, .swiftPM, .compilationDatabase,
4141
]
@@ -52,17 +52,17 @@ package func determineBuildSystem(
5252
switch buildSystemType {
5353
case .buildServer:
5454
if let projectRoot = ExternalBuildSystemAdapter.projectRoot(for: workspaceFolderPath, options: options) {
55-
return .buildServer(projectRoot: projectRoot)
55+
return BuildSystemSpec(kind: .buildServer, projectRoot: projectRoot)
5656
}
5757
case .compilationDatabase:
5858
if let projectRoot = CompilationDatabaseBuildSystem.projectRoot(for: workspaceFolderPath, options: options) {
59-
return .compilationDatabase(projectRoot: projectRoot)
59+
return BuildSystemSpec(kind: .compilationDatabase, projectRoot: projectRoot)
6060
}
6161
case .swiftPM:
6262
if let projectRootURL = SwiftPMBuildSystem.projectRoot(for: workspaceFolderUrl, options: options),
6363
let projectRoot = try? AbsolutePath(validating: projectRootURL.filePath)
6464
{
65-
return .swiftPM(projectRoot: projectRoot)
65+
return BuildSystemSpec(kind: .swiftPM, projectRoot: projectRoot)
6666
}
6767
}
6868
}

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,16 @@ package actor SourceKitLSPServer {
229229
// was added to it and thus currently doesn't know that it can handle that file. In that case, we shouldn't open
230230
// a new workspace for the same root. Instead, the existing workspace's build system needs to be reloaded.
231231
let uri = DocumentURI(url)
232-
guard let buildSystemKind = determineBuildSystem(forWorkspaceFolder: uri, options: self.options) else {
232+
guard let buildSystemSpec = determineBuildSystem(forWorkspaceFolder: uri, options: self.options) else {
233233
continue
234234
}
235-
guard !projectRoots.contains(buildSystemKind.projectRoot) else {
235+
guard !projectRoots.contains(buildSystemSpec.projectRoot) else {
236236
continue
237237
}
238238
guard
239239
let workspace = await orLog(
240240
"Creating workspace",
241-
{ try await createWorkspace(workspaceFolder: uri, buildSystemKind: buildSystemKind) }
241+
{ try await createWorkspace(workspaceFolder: uri, buildSystemSpec: buildSystemSpec) }
242242
)
243243
else {
244244
continue
@@ -809,7 +809,7 @@ extension SourceKitLSPServer {
809809
/// If the build system that was determined for the workspace does not satisfy `condition`, `nil` is returned.
810810
private func createWorkspace(
811811
workspaceFolder: DocumentURI,
812-
buildSystemKind: BuildSystemKind?
812+
buildSystemSpec: BuildSystemSpec?
813813
) async throws -> Workspace {
814814
guard let capabilityRegistry = capabilityRegistry else {
815815
struct NoCapabilityRegistryError: Error {}
@@ -833,7 +833,7 @@ extension SourceKitLSPServer {
833833
documentManager: self.documentManager,
834834
rootUri: workspaceFolder,
835835
capabilityRegistry: capabilityRegistry,
836-
buildSystemKind: buildSystemKind,
836+
buildSystemSpec: buildSystemSpec,
837837
toolchainRegistry: self.toolchainRegistry,
838838
options: options,
839839
testHooks: testHooks,
@@ -918,7 +918,7 @@ extension SourceKitLSPServer {
918918
await orLog("Creating workspace from workspaceFolders") {
919919
let workspace = try await self.createWorkspace(
920920
workspaceFolder: workspaceFolder.uri,
921-
buildSystemKind: determineBuildSystem(forWorkspaceFolder: workspaceFolder.uri, options: self.options)
921+
buildSystemSpec: determineBuildSystem(forWorkspaceFolder: workspaceFolder.uri, options: self.options)
922922
)
923923
return (workspace: workspace, isImplicit: false)
924924
}
@@ -927,7 +927,7 @@ extension SourceKitLSPServer {
927927
let workspace = await orLog("Creating workspace from rootURI") {
928928
try await self.createWorkspace(
929929
workspaceFolder: uri,
930-
buildSystemKind: determineBuildSystem(forWorkspaceFolder: uri, options: self.options)
930+
buildSystemSpec: determineBuildSystem(forWorkspaceFolder: uri, options: self.options)
931931
)
932932
}
933933
if let workspace {
@@ -938,7 +938,7 @@ extension SourceKitLSPServer {
938938
let workspace = await orLog("Creating workspace from rootPath") {
939939
try await self.createWorkspace(
940940
workspaceFolder: uri,
941-
buildSystemKind: determineBuildSystem(forWorkspaceFolder: uri, options: self.options)
941+
buildSystemSpec: determineBuildSystem(forWorkspaceFolder: uri, options: self.options)
942942
)
943943
}
944944
if let workspace {
@@ -955,7 +955,7 @@ extension SourceKitLSPServer {
955955
documentManager: self.documentManager,
956956
rootUri: req.rootURI,
957957
capabilityRegistry: self.capabilityRegistry!,
958-
buildSystemKind: nil,
958+
buildSystemSpec: nil,
959959
toolchainRegistry: self.toolchainRegistry,
960960
options: options,
961961
testHooks: testHooks,
@@ -1342,7 +1342,7 @@ extension SourceKitLSPServer {
13421342
await orLog("Creating workspace after workspace folder change") {
13431343
try await self.createWorkspace(
13441344
workspaceFolder: workspaceFolder.uri,
1345-
buildSystemKind: determineBuildSystem(forWorkspaceFolder: workspaceFolder.uri, options: self.options)
1345+
buildSystemSpec: determineBuildSystem(forWorkspaceFolder: workspaceFolder.uri, options: self.options)
13461346
)
13471347
}
13481348
}

Sources/SourceKitLSP/Workspace.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate {
172172
documentManager: DocumentManager,
173173
rootUri: DocumentURI?,
174174
capabilityRegistry: CapabilityRegistry,
175-
buildSystemKind: BuildSystemKind?,
175+
buildSystemSpec: BuildSystemSpec?,
176176
toolchainRegistry: ToolchainRegistry,
177177
options: SourceKitLSPOptions,
178178
testHooks: TestHooks,
@@ -222,15 +222,15 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate {
222222
}
223223

224224
let buildSystemManager = await BuildSystemManager(
225-
buildSystemKind: buildSystemKind,
225+
buildSystemSpec: buildSystemSpec,
226226
toolchainRegistry: toolchainRegistry,
227227
options: options,
228228
connectionToClient: ConnectionToClient(sourceKitLSPServer: sourceKitLSPServer),
229229
buildSystemTestHooks: testHooks.buildSystemTestHooks
230230
)
231231

232232
logger.log(
233-
"Created workspace at \(rootUri.forLogging) with project root \(buildSystemKind?.projectRoot.pathString ?? "<nil>")"
233+
"Created workspace at \(rootUri.forLogging) with project root \(buildSystemSpec?.projectRoot.pathString ?? "<nil>")"
234234
)
235235

236236
var index: IndexStoreDB? = nil

Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class BuildSystemManagerTests: XCTestCase {
4444
)
4545

4646
let bsm = await BuildSystemManager(
47-
buildSystemKind: nil,
47+
buildSystemSpec: nil,
4848
toolchainRegistry: ToolchainRegistry.forTesting,
4949
options: SourceKitLSPOptions(),
5050
connectionToClient: DummyBuildSystemManagerConnectionToClient(),
@@ -103,7 +103,7 @@ final class BuildSystemManagerTests: XCTestCase {
103103
let a = try DocumentURI(string: "bsm:a.swift")
104104
let mainFiles = ManualMainFilesProvider([a: [a]])
105105
let bsm = await BuildSystemManager(
106-
buildSystemKind: .testBuildSystem(projectRoot: try AbsolutePath(validating: "/")),
106+
buildSystemSpec: BuildSystemSpec(kind: .testBuildSystem, projectRoot: try AbsolutePath(validating: "/")),
107107
toolchainRegistry: ToolchainRegistry.forTesting,
108108
options: SourceKitLSPOptions(),
109109
connectionToClient: DummyBuildSystemManagerConnectionToClient(),
@@ -136,7 +136,7 @@ final class BuildSystemManagerTests: XCTestCase {
136136
let a = try DocumentURI(string: "bsm:a.swift")
137137
let mainFiles = ManualMainFilesProvider([a: [a]])
138138
let bsm = await BuildSystemManager(
139-
buildSystemKind: .testBuildSystem(projectRoot: try AbsolutePath(validating: "/")),
139+
buildSystemSpec: BuildSystemSpec(kind: .testBuildSystem, projectRoot: try AbsolutePath(validating: "/")),
140140
toolchainRegistry: ToolchainRegistry.forTesting,
141141
options: SourceKitLSPOptions(),
142142
connectionToClient: DummyBuildSystemManagerConnectionToClient(),
@@ -158,7 +158,7 @@ final class BuildSystemManagerTests: XCTestCase {
158158
let a = try DocumentURI(string: "bsm:a.swift")
159159
let mainFiles = ManualMainFilesProvider([a: [a]])
160160
let bsm = await BuildSystemManager(
161-
buildSystemKind: .testBuildSystem(projectRoot: try AbsolutePath(validating: "/")),
161+
buildSystemSpec: BuildSystemSpec(kind: .testBuildSystem, projectRoot: try AbsolutePath(validating: "/")),
162162
toolchainRegistry: ToolchainRegistry.forTesting,
163163
options: SourceKitLSPOptions(),
164164
connectionToClient: DummyBuildSystemManagerConnectionToClient(),
@@ -202,7 +202,7 @@ final class BuildSystemManagerTests: XCTestCase {
202202
)
203203

204204
let bsm = await BuildSystemManager(
205-
buildSystemKind: .testBuildSystem(projectRoot: try AbsolutePath(validating: "/")),
205+
buildSystemSpec: BuildSystemSpec(kind: .testBuildSystem, projectRoot: try AbsolutePath(validating: "/")),
206206
toolchainRegistry: ToolchainRegistry.forTesting,
207207
options: SourceKitLSPOptions(),
208208
connectionToClient: DummyBuildSystemManagerConnectionToClient(),
@@ -266,7 +266,7 @@ final class BuildSystemManagerTests: XCTestCase {
266266
)
267267

268268
let bsm = await BuildSystemManager(
269-
buildSystemKind: .testBuildSystem(projectRoot: try AbsolutePath(validating: "/")),
269+
buildSystemSpec: BuildSystemSpec(kind: .testBuildSystem, projectRoot: try AbsolutePath(validating: "/")),
270270
toolchainRegistry: ToolchainRegistry.forTesting,
271271
options: SourceKitLSPOptions(),
272272
connectionToClient: DummyBuildSystemManagerConnectionToClient(),

0 commit comments

Comments
 (0)