diff --git a/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift b/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift index cd35fd81..ac9b9e4d 100644 --- a/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift +++ b/Sources/BuildSystemIntegration/BuildServerBuildSystem.swift @@ -333,11 +333,6 @@ extension BuildServerBuildSystem: BuiltInBuildSystem { package func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse { return VoidResponse() } - - package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) { - // BuildServerBuildSystem does not support syntactic test discovery or background indexing. - // (https://github.com/swiftlang/sourcekit-lsp/issues/1173). - } } private func loadBuildServerConfig(path: AbsolutePath, fileSystem: FileSystem) throws -> BuildServerConfig { diff --git a/Sources/BuildSystemIntegration/BuildSystemDelegate.swift b/Sources/BuildSystemIntegration/BuildSystemDelegate.swift index b37778e5..fc947f33 100644 --- a/Sources/BuildSystemIntegration/BuildSystemDelegate.swift +++ b/Sources/BuildSystemIntegration/BuildSystemDelegate.swift @@ -32,4 +32,7 @@ package protocol BuildSystemManagerDelegate: AnyObject, Sendable { /// Log the given message to the client's index log. func logMessageToIndexLog(taskID: IndexTaskID, message: String) + + /// Notify the delegate that the list of source files in the build system might have changed. + func sourceFilesDidChange() async } diff --git a/Sources/BuildSystemIntegration/BuildSystemManager.swift b/Sources/BuildSystemIntegration/BuildSystemManager.swift index f4516cf8..e0e2dadf 100644 --- a/Sources/BuildSystemIntegration/BuildSystemManager.swift +++ b/Sources/BuildSystemIntegration/BuildSystemManager.swift @@ -709,6 +709,7 @@ extension BuildSystemManager { // FIXME: (BSP Migration) Communicate that the build target has changed to the `BuildSystemManagerDelegate` and make // it responsible for figuring out which files are affected. await delegate?.fileBuildSettingsChanged(Set(watchedFiles.keys)) + await self.delegate?.sourceFilesDidChange() } private func logMessage(notification: BuildServerProtocol.LogMessageNotification) async { diff --git a/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift b/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift index 41ff1c80..0d9fd420 100644 --- a/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift +++ b/Sources/BuildSystemIntegration/BuiltInBuildSystem.swift @@ -104,9 +104,4 @@ package protocol BuiltInBuildSystem: AnyObject, Sendable { /// Wait until the build graph has been loaded. func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse - - /// Adds a callback that should be called when the value returned by `sourceFiles()` changes. - /// - /// The callback might also be called without an actual change to `sourceFiles`. - func addSourceFilesDidChangeCallback(_ callback: @Sendable @escaping () async -> Void) async } diff --git a/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift b/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift index 28a9f227..2647332d 100644 --- a/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift +++ b/Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift @@ -206,8 +206,4 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem { await testFilesDidChangeCallback() } } - - package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) async { - testFilesDidChangeCallbacks.append(callback) - } } diff --git a/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift b/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift index a42f0807..95af08e6 100644 --- a/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift +++ b/Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift @@ -795,10 +795,6 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem { } } - package func addSourceFilesDidChangeCallback(_ callback: @Sendable @escaping () async -> Void) async { - testFilesDidChangeCallbacks.append(callback) - } - /// Retrieve settings for a package manifest (Package.swift). private func settings(forPackageManifest path: AbsolutePath) throws -> SourceKitOptionsResponse? { let compilerArgs = workspace.interpreterFlags(for: path.parentDirectory) + [path.pathString] diff --git a/Sources/BuildSystemIntegration/TestBuildSystem.swift b/Sources/BuildSystemIntegration/TestBuildSystem.swift index f0baad43..d8f48d0a 100644 --- a/Sources/BuildSystemIntegration/TestBuildSystem.swift +++ b/Sources/BuildSystemIntegration/TestBuildSystem.swift @@ -77,6 +77,4 @@ package actor TestBuildSystem: BuiltInBuildSystem { package func topologicalSort(of targets: [BuildTargetIdentifier]) -> [BuildTargetIdentifier]? { return nil } - - package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) async {} } diff --git a/Sources/SourceKitLSP/Workspace.swift b/Sources/SourceKitLSP/Workspace.swift index fa1fc6f7..c58ec8c1 100644 --- a/Sources/SourceKitLSP/Workspace.swift +++ b/Sources/SourceKitLSP/Workspace.swift @@ -130,15 +130,6 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate { await indexDelegate?.addMainFileChangedCallback { [weak self] in await self?.buildSystemManager.mainFilesChanged() } - await buildSystemManager.buildSystem?.underlyingBuildSystem.addSourceFilesDidChangeCallback { [weak self] in - guard let self else { - return - } - guard let testFiles = await orLog("Getting test files", { try await self.buildSystemManager.testFiles() }) else { - return - } - await self.syntacticTestIndex.listOfTestFilesDidChange(testFiles) - } // Trigger an initial population of `syntacticTestIndex`. if let testFiles = await orLog("Getting initial test files", { try await self.buildSystemManager.testFiles() }) { await syntacticTestIndex.listOfTestFilesDidChange(testFiles) @@ -328,6 +319,11 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate { package func logMessageToIndexLog(taskID: IndexTaskID, message: String) { self.logMessageToIndexLogCallback(taskID, message) } + + package func sourceFilesDidChange() async { + let testFiles = await orLog("Getting test files") { try await buildSystemManager.testFiles() } ?? [] + await syntacticTestIndex.listOfTestFilesDidChange(testFiles) + } } /// Wrapper around a workspace that isn't being retained. diff --git a/Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift b/Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift index b11a4858..3728ec59 100644 --- a/Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift +++ b/Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift @@ -406,4 +406,6 @@ private actor BSMDelegate: BuildSystemManagerDelegate { func buildTargetsChanged(_ changes: [BuildTargetEvent]?) async {} nonisolated func logMessageToIndexLog(taskID: BuildSystemIntegration.IndexTaskID, message: String) {} + + func sourceFilesDidChange() async {} }