@@ -34,14 +34,16 @@ import os
34
34
/// Since some `BuildSystem`s may require a bit of a time to compute their arguments asynchronously,
35
35
/// this class has a configurable `buildSettings` timeout which denotes the amount of time to give
36
36
/// the build system before applying the fallback arguments.
37
- package actor BuildSystemManager {
37
+ package actor BuildSystemManager : BuiltInBuildSystemAdapterDelegate {
38
38
/// The files for which the delegate has requested change notifications, ie.
39
39
/// the files for which the delegate wants to get `filesDependenciesUpdated`
40
40
/// callbacks if the file's build settings.
41
41
var watchedFiles : [ DocumentURI : ( mainFile: DocumentURI , language: Language ) ] = [ : ]
42
42
43
43
/// The underlying primary build system.
44
- let buildSystem : BuiltInBuildSystem ?
44
+ ///
45
+ /// - Important: The only time this should be modified is in the initializer. Afterwards, it must be constant.
46
+ private( set) var buildSystem : BuiltInBuildSystemAdapter ?
45
47
46
48
/// Timeout before fallback build settings are used.
47
49
let fallbackSettingsTimeout : DispatchTimeInterval
@@ -66,12 +68,12 @@ package actor BuildSystemManager {
66
68
/// was found.
67
69
package var projectRoot : AbsolutePath ? {
68
70
get async {
69
- return await buildSystem? . projectRoot
71
+ return await buildSystem? . underlyingBuildSystem . projectRoot
70
72
}
71
73
}
72
74
73
75
package var supportsPreparation : Bool {
74
- return buildSystem? . supportsPreparation ?? false
76
+ return buildSystem? . underlyingBuildSystem . supportsPreparation ?? false
75
77
}
76
78
77
79
/// Create a BuildSystemManager that wraps the given build system. The new
@@ -85,28 +87,45 @@ package actor BuildSystemManager {
85
87
) async {
86
88
let buildSystemHasDelegate = await buildSystem? . delegate != nil
87
89
precondition ( !buildSystemHasDelegate)
88
- self . buildSystem = buildSystem
89
90
self . fallbackBuildSystem = fallbackBuildSystem
90
91
self . mainFilesProvider = mainFilesProvider
91
92
self . toolchainRegistry = toolchainRegistry
92
93
self . fallbackSettingsTimeout = fallbackSettingsTimeout
93
- await self . buildSystem? . setDelegate ( self )
94
+ self . buildSystem =
95
+ if let buildSystem {
96
+ await BuiltInBuildSystemAdapter ( buildSystem: buildSystem, messageHandler: self )
97
+ } else {
98
+ nil
99
+ }
100
+ await self . buildSystem? . underlyingBuildSystem. setDelegate ( self )
94
101
}
95
102
96
103
package func filesDidChange( _ events: [ FileEvent ] ) async {
97
- await self . buildSystem? . filesDidChange ( events)
104
+ await self . buildSystem? . underlyingBuildSystem. filesDidChange ( events)
105
+ }
106
+
107
+ /// Implementation of `MessageHandler`, handling notifications from the build system.
108
+ ///
109
+ /// - Important: Do not call directly.
110
+ package func handle( _ notification: some LanguageServerProtocol . NotificationType ) {
111
+ logger. error ( " Ignoring unknown notification \( type ( of: notification) . method) from build system " )
112
+ }
113
+
114
+ /// Implementation of `MessageHandler`, handling requests from the build system.
115
+ ///
116
+ /// - Important: Do not call directly.
117
+ package nonisolated func handle< R: RequestType > ( _ request: R ) async throws -> R . Response {
118
+ throw ResponseError . methodNotFound ( R . method)
98
119
}
99
- }
100
120
101
- extension BuildSystemManager {
102
121
/// - Note: Needed so we can set the delegate from a different isolation context.
103
122
package func setDelegate( _ delegate: BuildSystemDelegate ? ) {
104
123
self . delegate = delegate
105
124
}
106
125
107
126
/// Returns the toolchain that should be used to process the given document.
108
127
package func toolchain( for uri: DocumentURI , _ language: Language ) async -> Toolchain ? {
109
- if let toolchain = await buildSystem? . toolchain ( for: uri, language) {
128
+ if let toolchain = await buildSystem? . underlyingBuildSystem . toolchain ( for: uri, language) {
110
129
return toolchain
111
130
}
112
131
@@ -128,7 +147,7 @@ extension BuildSystemManager {
128
147
/// Returns the language that a document should be interpreted in for background tasks where the editor doesn't
129
148
/// specify the document's language.
130
149
package func defaultLanguage( for document: DocumentURI ) async -> Language ? {
131
- if let defaultLanguage = await buildSystem? . defaultLanguage ( for: document) {
150
+ if let defaultLanguage = await buildSystem? . underlyingBuildSystem . defaultLanguage ( for: document) {
132
151
return defaultLanguage
133
152
}
134
153
switch document. fileURL? . pathExtension {
@@ -143,7 +162,7 @@ extension BuildSystemManager {
143
162
144
163
/// Returns all the `ConfiguredTarget`s that the document is part of.
145
164
package func configuredTargets( for document: DocumentURI ) async -> [ ConfiguredTarget ] {
146
- return await buildSystem? . configuredTargets ( for: document) ?? [ ]
165
+ return await buildSystem? . underlyingBuildSystem . configuredTargets ( for: document) ?? [ ]
147
166
}
148
167
149
168
/// Returns the `ConfiguredTarget` that should be used for semantic functionality of the given document.
@@ -203,7 +222,7 @@ extension BuildSystemManager {
203
222
// For now, this should be fine because all build systems return
204
223
// very quickly from `settings(for:language:)`.
205
224
// https://github.com/apple/sourcekit-lsp/issues/1181
206
- return try await buildSystem. buildSettings ( for: document, in: target, language: language)
225
+ return try await buildSystem. underlyingBuildSystem . buildSettings ( for: document, in: target, language: language)
207
226
}
208
227
209
228
/// Returns the build settings for the given file in the given target.
@@ -266,26 +285,26 @@ extension BuildSystemManager {
266
285
}
267
286
268
287
package func generateBuildGraph( ) async throws {
269
- try await self . buildSystem? . generateBuildGraph ( )
288
+ try await self . buildSystem? . underlyingBuildSystem . generateBuildGraph ( )
270
289
}
271
290
272
291
package func waitForUpToDateBuildGraph( ) async {
273
- await self . buildSystem? . waitForUpToDateBuildGraph ( )
292
+ await self . buildSystem? . underlyingBuildSystem . waitForUpToDateBuildGraph ( )
274
293
}
275
294
276
295
package func topologicalSort( of targets: [ ConfiguredTarget ] ) async throws -> [ ConfiguredTarget ] ? {
277
- return await buildSystem? . topologicalSort ( of: targets)
296
+ return await buildSystem? . underlyingBuildSystem . topologicalSort ( of: targets)
278
297
}
279
298
280
299
package func targets( dependingOn targets: [ ConfiguredTarget ] ) async -> [ ConfiguredTarget ] ? {
281
- return await buildSystem? . targets ( dependingOn: targets)
300
+ return await buildSystem? . underlyingBuildSystem . targets ( dependingOn: targets)
282
301
}
283
302
284
303
package func prepare(
285
304
targets: [ ConfiguredTarget ] ,
286
305
logMessageToIndexLog: @escaping @Sendable ( _ taskID: IndexTaskID , _ message: String ) -> Void
287
306
) async throws {
288
- try await buildSystem? . prepare ( targets: targets, logMessageToIndexLog: logMessageToIndexLog)
307
+ try await buildSystem? . underlyingBuildSystem . prepare ( targets: targets, logMessageToIndexLog: logMessageToIndexLog)
289
308
}
290
309
291
310
package func registerForChangeNotifications( for uri: DocumentURI , language: Language ) async {
@@ -297,7 +316,7 @@ extension BuildSystemManager {
297
316
// system. That way, iff the main file changes, we will also notify the
298
317
// delegate about build setting changes of all header files that are based
299
318
// on that main file.
300
- await buildSystem? . registerForChangeNotifications ( for: mainFile)
319
+ await buildSystem? . underlyingBuildSystem . registerForChangeNotifications ( for: mainFile)
301
320
}
302
321
303
322
package func unregisterForChangeNotifications( for uri: DocumentURI ) async {
@@ -310,19 +329,19 @@ extension BuildSystemManager {
310
329
if watchedFilesReferencing ( mainFiles: [ mainFile] ) . isEmpty {
311
330
// Nobody is interested in this main file anymore.
312
331
// We are no longer interested in change notifications for it.
313
- await self . buildSystem? . unregisterForChangeNotifications ( for: mainFile)
332
+ await self . buildSystem? . underlyingBuildSystem . unregisterForChangeNotifications ( for: mainFile)
314
333
}
315
334
}
316
335
317
336
package func fileHandlingCapability( for uri: DocumentURI ) async -> FileHandlingCapability {
318
337
return max (
319
- await buildSystem? . fileHandlingCapability ( for: uri) ?? . unhandled,
338
+ await buildSystem? . underlyingBuildSystem . fileHandlingCapability ( for: uri) ?? . unhandled,
320
339
fallbackBuildSystem != nil ? . fallback : . unhandled
321
340
)
322
341
}
323
342
324
343
package func sourceFiles( ) async -> [ SourceFileInfo ] {
325
- return await buildSystem? . sourceFiles ( ) ?? [ ]
344
+ return await buildSystem? . underlyingBuildSystem . sourceFiles ( ) ?? [ ]
326
345
}
327
346
328
347
package func testFiles( ) async -> [ DocumentURI ] {
0 commit comments