Skip to content

Commit fac21f5

Browse files
committed
Implement waitForUpToDateBuildGraph using BSP
1 parent 12923b6 commit fac21f5

10 files changed

+50
-7
lines changed

Sources/BuildServerProtocol/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ add_library(BuildServerProtocol STATIC
1010
PrepareTargetsRequest.swift
1111
RegisterForChangeNotifications.swift
1212
ShutdownBuild.swift
13-
SourceKitOptionsRequest.swift)
13+
SourceKitOptionsRequest.swift
14+
WaitForBuildSystemUpdates.swift)
1415
set_target_properties(BuildServerProtocol PROPERTIES
1516
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
1617
target_link_libraries(BuildServerProtocol PRIVATE
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import LanguageServerProtocol
14+
15+
/// This request is a no-op and doesn't have any effects.
16+
///
17+
/// If the build system is currently updating the build graph, this request should return after those updates have
18+
/// finished processing.
19+
public struct WaitForBuildSystemUpdatesRequest: RequestType, Hashable {
20+
public typealias Response = VoidResponse
21+
22+
public static let method: String = "workspace/waitForBuildSystemUpdates"
23+
24+
public init() {}
25+
}

Sources/BuildSystemIntegration/BuildServerBuildSystem.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ extension BuildServerBuildSystem: BuiltInBuildSystem {
330330
)
331331
}
332332

333-
package func waitForUpToDateBuildGraph() async {}
333+
package func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse {
334+
return VoidResponse()
335+
}
334336

335337
package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) {
336338
// BuildServerBuildSystem does not support syntactic test discovery or background indexing.

Sources/BuildSystemIntegration/BuildSystemManager.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ package actor BuildSystemManager: BuiltInBuildSystemAdapterDelegate {
176176
}
177177
await delegate.filesDependenciesUpdated(changedWatchedFiles)
178178
}
179+
180+
// FIXME: (BSP migration) Forward file watch patterns from this initialize request to the client
179181
initializeResult = Task { () -> InitializeBuildResponse? in
180182
guard let buildSystem else {
181183
return nil
@@ -511,7 +513,9 @@ package actor BuildSystemManager: BuiltInBuildSystemAdapterDelegate {
511513
}
512514

513515
package func waitForUpToDateBuildGraph() async {
514-
await self.buildSystem?.underlyingBuildSystem.waitForUpToDateBuildGraph()
516+
await orLog("Waiting for build system updates") {
517+
let _: VoidResponse? = try await self.buildSystem?.send(WaitForBuildSystemUpdatesRequest())
518+
}
515519
}
516520

517521
/// The root targets of the project have depth of 0 and all target dependencies have a greater depth than the target

Sources/BuildSystemIntegration/BuiltInBuildSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ package protocol BuiltInBuildSystem: AnyObject, Sendable {
103103
func sourceKitOptions(request: SourceKitOptionsRequest) async throws -> SourceKitOptionsResponse?
104104

105105
/// Wait until the build graph has been loaded.
106-
func waitForUpToDateBuildGraph() async
106+
func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse
107107

108108
/// Adds a callback that should be called when the value returned by `sourceFiles()` changes.
109109
///

Sources/BuildSystemIntegration/BuiltInBuildSystemAdapter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ package actor BuiltInBuildSystemAdapter: BuiltInBuildSystemMessageHandler {
165165
return try await handle(request, underlyingBuildSystem.prepare)
166166
case let request as SourceKitOptionsRequest:
167167
return try await handle(request, underlyingBuildSystem.sourceKitOptions)
168+
case let request as WaitForBuildSystemUpdatesRequest:
169+
return try await handle(request, underlyingBuildSystem.waitForUpBuildSystemUpdates)
168170
default:
169171
throw ResponseError.methodNotFound(R.method)
170172
}

Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
153153
)
154154
}
155155

156-
package func waitForUpToDateBuildGraph() async {}
156+
package func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse {
157+
return VoidResponse()
158+
}
157159

158160
private func database(for uri: DocumentURI) -> CompilationDatabase? {
159161
if let url = uri.fileURL, let path = try? AbsolutePath(validating: url.path) {

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,9 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
629629
return InverseSourcesResponse(targets: targets(for: request.textDocument.uri))
630630
}
631631

632-
package func waitForUpToDateBuildGraph() async {
632+
package func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse {
633633
await self.packageLoadingQueue.async {}.valuePropagatingCancellation
634+
return VoidResponse()
634635
}
635636

636637
package func prepare(request: PrepareTargetsRequest) async throws -> VoidResponse {

Sources/BuildSystemIntegration/TestBuildSystem.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ package actor TestBuildSystem: BuiltInBuildSystem {
7070
return buildSettingsByFile[request.textDocument.uri]
7171
}
7272

73-
package func waitForUpToDateBuildGraph() async {}
73+
package func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse {
74+
return VoidResponse()
75+
}
7476

7577
package func topologicalSort(of targets: [BuildTargetIdentifier]) -> [BuildTargetIdentifier]? {
7678
return nil

Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ fileprivate extension SwiftPMBuildSystem {
3737
request: SourceKitOptionsRequest(textDocument: TextDocumentIdentifier(uri: uri), target: target)
3838
)
3939
}
40+
41+
func waitForUpToDateBuildGraph() async {
42+
let _: VoidResponse = await self.waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest())
43+
}
4044
}
4145

4246
final class SwiftPMBuildSystemTests: XCTestCase {

0 commit comments

Comments
 (0)