@@ -142,10 +142,9 @@ private enum BuildSystemAdapter {
142142}
143143
144144private extension BuildSystemSpec {
145- private static func createBuiltInBuildSystemAdapter(
146- projectRoot: URL ,
145+ private func createBuiltInBuildSystemAdapter(
147146 messagesToSourceKitLSPHandler: any MessageHandler ,
148- buildSystemTestHooks : BuildSystemTestHooks ,
147+ buildSystemHooks : BuildSystemHooks ,
149148 _ createBuildSystem: @Sendable ( _ connectionToSourceKitLSP: any Connection ) async throws -> BuiltInBuildSystem ?
150149 ) async -> BuildSystemAdapter ? {
151150 let connectionToSourceKitLSP = LocalConnection (
@@ -164,7 +163,7 @@ private extension BuildSystemSpec {
164163 let buildSystemAdapter = BuiltInBuildSystemAdapter (
165164 underlyingBuildSystem: buildSystem,
166165 connectionToSourceKitLSP: connectionToSourceKitLSP,
167- buildSystemTestHooks : buildSystemTestHooks
166+ buildSystemHooks : buildSystemHooks
168167 )
169168 let connectionToBuildSystem = LocalConnection (
170169 receiverName: " \( type ( of: buildSystem) ) for \( projectRoot. lastPathComponent) "
@@ -178,14 +177,15 @@ private extension BuildSystemSpec {
178177 func createBuildSystemAdapter(
179178 toolchainRegistry: ToolchainRegistry ,
180179 options: SourceKitLSPOptions ,
181- buildSystemTestHooks testHooks : BuildSystemTestHooks ,
180+ buildSystemHooks : BuildSystemHooks ,
182181 messagesToSourceKitLSPHandler: any MessageHandler
183182 ) async -> BuildSystemAdapter ? {
184183 switch self . kind {
185184 case . buildServer:
186185 let buildSystem = await orLog ( " Creating external build system " ) {
187186 try await ExternalBuildSystemAdapter (
188187 projectRoot: projectRoot,
188+ configPath: configPath,
189189 messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler
190190 )
191191 }
@@ -196,40 +196,38 @@ private extension BuildSystemSpec {
196196 logger. log ( " Created external build server at \( projectRoot) " )
197197 return . external( buildSystem)
198198 case . compilationDatabase:
199- return await Self . createBuiltInBuildSystemAdapter (
200- projectRoot: projectRoot,
199+ return await createBuiltInBuildSystemAdapter (
201200 messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
202- buildSystemTestHooks : testHooks
201+ buildSystemHooks : buildSystemHooks
203202 ) { connectionToSourceKitLSP in
204- CompilationDatabaseBuildSystem (
205- projectRoot: projectRoot,
206- searchPaths: ( options. compilationDatabaseOrDefault. searchPaths ?? [ ] ) . compactMap {
207- try ? RelativePath ( validating: $0)
208- } ,
203+ try CompilationDatabaseBuildSystem (
204+ configPath: configPath,
209205 connectionToSourceKitLSP: connectionToSourceKitLSP
210206 )
211207 }
212208 case . swiftPM:
213- return await Self . createBuiltInBuildSystemAdapter (
214- projectRoot : projectRoot ,
209+ #if canImport(PackageModel)
210+ return await createBuiltInBuildSystemAdapter (
215211 messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
216- buildSystemTestHooks : testHooks
212+ buildSystemHooks : buildSystemHooks
217213 ) { connectionToSourceKitLSP in
218214 try await SwiftPMBuildSystem (
219215 projectRoot: projectRoot,
220216 toolchainRegistry: toolchainRegistry,
221217 options: options,
222218 connectionToSourceKitLSP: connectionToSourceKitLSP,
223- testHooks: testHooks . swiftPMTestHooks
219+ testHooks: buildSystemHooks . swiftPMTestHooks
224220 )
225221 }
226- case . testBuildSystem:
227- return await Self . createBuiltInBuildSystemAdapter (
228- projectRoot: projectRoot,
222+ #else
223+ return nil
224+ #endif
225+ case . injected( let injector) :
226+ return await createBuiltInBuildSystemAdapter (
229227 messagesToSourceKitLSPHandler: messagesToSourceKitLSPHandler,
230- buildSystemTestHooks : testHooks
228+ buildSystemHooks : buildSystemHooks
231229 ) { connectionToSourceKitLSP in
232- TestBuildSystem ( projectRoot: projectRoot, connectionToSourceKitLSP: connectionToSourceKitLSP)
230+ await injector . createBuildSystem ( projectRoot: projectRoot, connectionToSourceKitLSP: connectionToSourceKitLSP)
233231 }
234232 }
235233 }
@@ -244,13 +242,14 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
244242
245243 package let messageHandlingQueue = AsyncQueue < BuildSystemMessageDependencyTracker > ( )
246244
247- /// The root of the project that this build system manages.
245+ /// The path to the main configuration file (or directory) that this build system manages.
248246 ///
249- /// For example, in SwiftPM packages this is the folder containing Package.swift.
250- /// For compilation databases it is the root folder based on which the compilation database was found.
247+ /// Some examples:
248+ /// - The path to `Package.swift` for SwiftPM packages
249+ /// - The path to `compile_commands.json` for a JSON compilation database
251250 ///
252251 /// `nil` if the `BuildSystemManager` does not have an underlying build system.
253- package let projectRoot : URL ?
252+ package let configPath : URL ?
254253
255254 /// The files for which the delegate has requested change notifications, ie. the files for which the delegate wants to
256255 /// get `fileBuildSettingsChanged` and `filesDependenciesUpdated` callbacks.
@@ -271,19 +270,6 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
271270 }
272271 }
273272
274- /// If the underlying build system is a `TestBuildSystem`, return it. Otherwise, `nil`
275- ///
276- /// - Important: For testing purposes only.
277- package var testBuildSystem : TestBuildSystem ? {
278- get async {
279- switch buildSystemAdapter {
280- case . builtIn( let builtInBuildSystemAdapter, _) : return await builtInBuildSystemAdapter. testBuildSystem
281- case . external: return nil
282- case nil : return nil
283- }
284- }
285- }
286-
287273 /// Provider of file to main file mappings.
288274 private var mainFilesProvider : MainFilesProvider ?
289275
@@ -363,16 +349,16 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
363349 toolchainRegistry: ToolchainRegistry ,
364350 options: SourceKitLSPOptions ,
365351 connectionToClient: BuildSystemManagerConnectionToClient ,
366- buildSystemTestHooks : BuildSystemTestHooks
352+ buildSystemHooks : BuildSystemHooks
367353 ) async {
368354 self . toolchainRegistry = toolchainRegistry
369355 self . options = options
370356 self . connectionToClient = connectionToClient
371- self . projectRoot = buildSystemSpec? . projectRoot
357+ self . configPath = buildSystemSpec? . configPath
372358 self . buildSystemAdapter = await buildSystemSpec? . createBuildSystemAdapter (
373359 toolchainRegistry: toolchainRegistry,
374360 options: options,
375- buildSystemTestHooks : buildSystemTestHooks ,
361+ buildSystemHooks : buildSystemHooks ,
376362 messagesToSourceKitLSPHandler: WeakMessageHandler ( self )
377363 )
378364
@@ -422,13 +408,14 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
422408 logger. log ( " Launched a legacy BSP server. Using push-based build settings model. " )
423409 let legacyBuildServer = await LegacyBuildServerBuildSystem (
424410 projectRoot: buildSystemSpec. projectRoot,
411+ configPath: buildSystemSpec. configPath,
425412 initializationData: initializeResponse,
426413 externalBuildSystemAdapter
427414 )
428415 let adapter = BuiltInBuildSystemAdapter (
429416 underlyingBuildSystem: legacyBuildServer,
430417 connectionToSourceKitLSP: legacyBuildServer. connectionToSourceKitLSP,
431- buildSystemTestHooks : buildSystemTestHooks
418+ buildSystemHooks : buildSystemHooks
432419 )
433420 let connectionToBuildSystem = LocalConnection ( receiverName: " Legacy BSP server " )
434421 connectionToBuildSystem. start ( handler: adapter)
@@ -688,8 +675,8 @@ package actor BuildSystemManager: QueueBasedMessageHandler {
688675 result. formUnion ( targets)
689676 }
690677 if !filesAndDirectories. directories. isEmpty, let documentPathComponents = document. fileURL? . pathComponents {
691- for (directory , ( directoryPathComponents, info) ) in filesAndDirectories. directories {
692- guard let directoryPathComponents, let directoryPath = directory . fileURL else {
678+ for (_ , ( directoryPathComponents, info) ) in filesAndDirectories. directories {
679+ guard let directoryPathComponents else {
693680 continue
694681 }
695682 if isDescendant ( documentPathComponents, of: directoryPathComponents) {
0 commit comments