diff --git a/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift b/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift index 2952f6f1..9d509ecd 100644 --- a/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift +++ b/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift @@ -334,8 +334,6 @@ extension BuildServerBuildSystem: BuiltInBuildSystem { return nil } - package func scheduleBuildGraphGeneration() {} - package func waitForUpToDateBuildGraph() async {} package func topologicalSort(of targets: [BuildTargetIdentifier]) async -> [BuildTargetIdentifier]? { diff --git a/Sources/BuildSystemIntegration/BuildSystemManager.swift b/Sources/BuildSystemIntegration/BuildSystemManager.swift index c82c1095..bd3259fa 100644 --- a/Sources/BuildSystemIntegration/BuildSystemManager.swift +++ b/Sources/BuildSystemIntegration/BuildSystemManager.swift @@ -481,10 +481,6 @@ package actor BuildSystemManager: BuiltInBuildSystemAdapterDelegate { return settings } - package func scheduleBuildGraphGeneration() async throws { - try await self.buildSystem?.underlyingBuildSystem.scheduleBuildGraphGeneration() - } - package func waitForUpToDateBuildGraph() async { await self.buildSystem?.underlyingBuildSystem.waitForUpToDateBuildGraph() } diff --git a/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift b/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift index 2484e543..27cac68f 100644 --- a/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift +++ b/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift @@ -102,11 +102,6 @@ package protocol BuiltInBuildSystem: AnyObject, Sendable { /// file or if it hasn't computed build settings for the file yet. func sourceKitOptions(request: SourceKitOptionsRequest) async throws -> SourceKitOptionsResponse? - /// Schedule a task that re-generates the build graph. The function may return before the build graph has finished - /// being generated. If clients need to wait for an up-to-date build graph, they should call - /// `waitForUpToDateBuildGraph` afterwards. - func scheduleBuildGraphGeneration() async throws - /// Wait until the build graph has been loaded. func waitForUpToDateBuildGraph() async diff --git a/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift b/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift index 65b3ff92..f4cda242 100644 --- a/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift +++ b/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift @@ -157,8 +157,6 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem { return nil } - package func scheduleBuildGraphGeneration() {} - package func waitForUpToDateBuildGraph() async {} package func topologicalSort(of targets: [BuildTargetIdentifier]) -> [BuildTargetIdentifier]? { diff --git a/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift b/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift index 0b344f8e..c3c73a5a 100644 --- a/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift +++ b/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift @@ -361,6 +361,15 @@ package actor SwiftPMBuildSystem { ) self.reloadPackageStatusCallback = reloadPackageStatusCallback + + packageLoadingQueue.async { + await orLog("Initial package loading") { + // Schedule an initial generation of the build graph. Once the build graph is loaded, the build system will send + // call `fileHandlingCapabilityChanged`, which allows us to move documents to a workspace with this build + // system. + try await self.reloadPackageAssumingOnPackageLoadingQueue() + } + } } /// Creates a build system using the Swift Package Manager, if this workspace is a package. @@ -398,15 +407,9 @@ package actor SwiftPMBuildSystem { extension SwiftPMBuildSystem { /// (Re-)load the package settings by parsing the manifest and resolving all the targets and /// dependencies. - @discardableResult - package func schedulePackageReload() -> Task { - return packageLoadingQueue.asyncThrowing { - try await self.reloadPackageImpl() - } - } - + /// /// - Important: Must only be called on `packageLoadingQueue`. - private func reloadPackageImpl() async throws { + private func reloadPackageAssumingOnPackageLoadingQueue() async throws { await reloadPackageStatusCallback(.start) await testHooks.reloadPackageDidStart?() defer { @@ -620,10 +623,6 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem { return InverseSourcesResponse(targets: targets(for: request.textDocument.uri)) } - package func scheduleBuildGraphGeneration() async throws { - self.schedulePackageReload() - } - package func waitForUpToDateBuildGraph() async { await self.packageLoadingQueue.async {}.valuePropagatingCancellation } @@ -810,9 +809,11 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem { package func didChangeWatchedFiles(notification: BuildServerProtocol.DidChangeWatchedFilesNotification) async { if notification.changes.contains(where: { self.fileEventShouldTriggerPackageReload(event: $0) }) { logger.log("Reloading package because of file change") - await orLog("Reloading package") { - try await self.schedulePackageReload().value - } + await packageLoadingQueue.async { + await orLog("Reloading package") { + try await self.reloadPackageAssumingOnPackageLoadingQueue() + } + }.valuePropagatingCancellation } } diff --git a/Sources/BuildSystemIntegration/TestBuildSystem.swift b/Sources/BuildSystemIntegration/TestBuildSystem.swift index cf7873e4..f278b8b4 100644 --- a/Sources/BuildSystemIntegration/TestBuildSystem.swift +++ b/Sources/BuildSystemIntegration/TestBuildSystem.swift @@ -74,8 +74,6 @@ package actor TestBuildSystem: BuiltInBuildSystem { return nil } - package func scheduleBuildGraphGeneration() {} - package func waitForUpToDateBuildGraph() async {} package func topologicalSort(of targets: [BuildTargetIdentifier]) -> [BuildTargetIdentifier]? { diff --git a/Sources/SourceKitLSP/Workspace.swift b/Sources/SourceKitLSP/Workspace.swift index 339f36dc..fa1fc6f7 100644 --- a/Sources/SourceKitLSP/Workspace.swift +++ b/Sources/SourceKitLSP/Workspace.swift @@ -178,13 +178,6 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate { ) let buildSystem = await buildSystemManager.buildSystem?.underlyingBuildSystem - await orLog("Initial build graph generation") { - // Schedule an initial generation of the build graph. Once the build graph is loaded, the build system will send - // call `fileHandlingCapabilityChanged`, which allows us to move documents to a workspace with this build - // system. - try await buildSystem?.scheduleBuildGraphGeneration() - } - let buildSystemType = if let buildSystem { String(describing: type(of: buildSystem)) diff --git a/Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift b/Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift index 6aa0030c..fa4afee9 100644 --- a/Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift +++ b/Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift @@ -54,34 +54,6 @@ final class SwiftPMBuildSystemTests: XCTestCase { } } - func testUnparsablePackage() async throws { - let fs = localFileSystem - try await withTestScratchDir { tempDir in - try fs.createFiles( - root: tempDir, - files: [ - "pkg/Sources/lib/a.swift": "", - "pkg/Package.swift": """ - // swift-tools-version:4.2 - import PackageDescription - let pack - """, - ] - ) - let packageRoot = tempDir.appending(component: "pkg") - let tr = ToolchainRegistry.forTesting - let buildSystem = try await SwiftPMBuildSystem( - projectRoot: packageRoot, - toolchainRegistry: tr, - fileSystem: fs, - options: SourceKitLSPOptions(), - messageHandler: nil, - testHooks: SwiftPMTestHooks() - ) - await assertThrowsError(try await buildSystem.schedulePackageReload().value) - } - } - func testNoToolchain() async throws { let fs = localFileSystem try await withTestScratchDir { tempDir in @@ -141,7 +113,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift") let hostTriple = await swiftpmBuildSystem.destinationBuildParameters.triple @@ -207,7 +179,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aPlusSomething = packageRoot.appending(components: "Sources", "lib", "a+something.swift") let hostTriple = await swiftpmBuildSystem.destinationBuildParameters.triple @@ -270,7 +242,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift") let hostTriple = await swiftpmBuildSystem.destinationBuildParameters.triple @@ -354,7 +326,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let source = try resolveSymlinks(packageRoot.appending(component: "Package.swift")) let arguments = try await unwrap(swiftpmBuildSystem.buildSettings(for: source.asURI)) @@ -392,7 +364,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift") let bswift = packageRoot.appending(components: "Sources", "lib", "b.swift") @@ -442,7 +414,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "libA", "a.swift") let bswift = packageRoot.appending(components: "Sources", "libB", "b.swift") @@ -498,7 +470,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "libA", "a.swift") let bswift = packageRoot.appending(components: "Sources", "libB", "b.swift") @@ -538,7 +510,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let acxx = packageRoot.appending(components: "Sources", "lib", "a.cpp") let bcxx = packageRoot.appending(components: "Sources", "lib", "b.cpp") @@ -620,7 +592,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift") let arguments = try await unwrap(swiftpmBuildSystem.buildSettings(for: aswift.asURI)) @@ -673,7 +645,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift1 = packageRoot.appending(components: "Sources", "lib", "a.swift") let aswift2 = @@ -742,7 +714,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() for file in [acpp, ah] { let args = try unwrap( @@ -783,7 +755,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift") let arguments = try await unwrap(swiftpmBuildSystem.buildSettings(for: aswift.asURI)) @@ -852,7 +824,7 @@ final class SwiftPMBuildSystemTests: XCTestCase { messageHandler: nil, testHooks: SwiftPMTestHooks() ) - try await swiftpmBuildSystem.schedulePackageReload().value + await swiftpmBuildSystem.waitForUpToDateBuildGraph() let aswift = packageRoot.appending(components: "Plugins", "MyPlugin", "a.swift") let hostTriple = await swiftpmBuildSystem.destinationBuildParameters.triple