Skip to content

Commit a96c091

Browse files
committed
Implement addSourceFilesDidChangeCallback in BuildSystemManager
1 parent fac21f5 commit a96c091

File tree

9 files changed

+11
-29
lines changed

9 files changed

+11
-29
lines changed

Sources/BuildSystemIntegration/BuildServerBuildSystem.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,6 @@ extension BuildServerBuildSystem: BuiltInBuildSystem {
333333
package func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse {
334334
return VoidResponse()
335335
}
336-
337-
package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) {
338-
// BuildServerBuildSystem does not support syntactic test discovery or background indexing.
339-
// (https://github.com/swiftlang/sourcekit-lsp/issues/1173).
340-
}
341336
}
342337

343338
private func loadBuildServerConfig(path: AbsolutePath, fileSystem: FileSystem) throws -> BuildServerConfig {

Sources/BuildSystemIntegration/BuildSystemDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ package protocol BuildSystemManagerDelegate: AnyObject, Sendable {
3232

3333
/// Log the given message to the client's index log.
3434
func logMessageToIndexLog(taskID: IndexTaskID, message: String)
35+
36+
/// Notify the delegate that the list of source files in the build system might have changed.
37+
func sourceFilesDidChange() async
3538
}

Sources/BuildSystemIntegration/BuildSystemManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ extension BuildSystemManager {
709709
// FIXME: (BSP Migration) Communicate that the build target has changed to the `BuildSystemManagerDelegate` and make
710710
// it responsible for figuring out which files are affected.
711711
await delegate?.fileBuildSettingsChanged(Set(watchedFiles.keys))
712+
await self.delegate?.sourceFilesDidChange()
712713
}
713714

714715
private func logMessage(notification: BuildServerProtocol.LogMessageNotification) async {

Sources/BuildSystemIntegration/BuiltInBuildSystem.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,4 @@ package protocol BuiltInBuildSystem: AnyObject, Sendable {
104104

105105
/// Wait until the build graph has been loaded.
106106
func waitForUpBuildSystemUpdates(request: WaitForBuildSystemUpdatesRequest) async -> VoidResponse
107-
108-
/// Adds a callback that should be called when the value returned by `sourceFiles()` changes.
109-
///
110-
/// The callback might also be called without an actual change to `sourceFiles`.
111-
func addSourceFilesDidChangeCallback(_ callback: @Sendable @escaping () async -> Void) async
112107
}

Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,4 @@ extension CompilationDatabaseBuildSystem: BuiltInBuildSystem {
206206
await testFilesDidChangeCallback()
207207
}
208208
}
209-
210-
package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) async {
211-
testFilesDidChangeCallbacks.append(callback)
212-
}
213209
}

Sources/BuildSystemIntegration/SwiftPMBuildSystem.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,6 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuiltInBuildSystem {
795795
}
796796
}
797797

798-
package func addSourceFilesDidChangeCallback(_ callback: @Sendable @escaping () async -> Void) async {
799-
testFilesDidChangeCallbacks.append(callback)
800-
}
801-
802798
/// Retrieve settings for a package manifest (Package.swift).
803799
private func settings(forPackageManifest path: AbsolutePath) throws -> SourceKitOptionsResponse? {
804800
let compilerArgs = workspace.interpreterFlags(for: path.parentDirectory) + [path.pathString]

Sources/BuildSystemIntegration/TestBuildSystem.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,4 @@ package actor TestBuildSystem: BuiltInBuildSystem {
7777
package func topologicalSort(of targets: [BuildTargetIdentifier]) -> [BuildTargetIdentifier]? {
7878
return nil
7979
}
80-
81-
package func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) async {}
8280
}

Sources/SourceKitLSP/Workspace.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,6 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate {
130130
await indexDelegate?.addMainFileChangedCallback { [weak self] in
131131
await self?.buildSystemManager.mainFilesChanged()
132132
}
133-
await buildSystemManager.buildSystem?.underlyingBuildSystem.addSourceFilesDidChangeCallback { [weak self] in
134-
guard let self else {
135-
return
136-
}
137-
guard let testFiles = await orLog("Getting test files", { try await self.buildSystemManager.testFiles() }) else {
138-
return
139-
}
140-
await self.syntacticTestIndex.listOfTestFilesDidChange(testFiles)
141-
}
142133
// Trigger an initial population of `syntacticTestIndex`.
143134
if let testFiles = await orLog("Getting initial test files", { try await self.buildSystemManager.testFiles() }) {
144135
await syntacticTestIndex.listOfTestFilesDidChange(testFiles)
@@ -328,6 +319,11 @@ package final class Workspace: Sendable, BuildSystemManagerDelegate {
328319
package func logMessageToIndexLog(taskID: IndexTaskID, message: String) {
329320
self.logMessageToIndexLogCallback(taskID, message)
330321
}
322+
323+
package func sourceFilesDidChange() async {
324+
let testFiles = await orLog("Getting test files") { try await buildSystemManager.testFiles() } ?? []
325+
await syntacticTestIndex.listOfTestFilesDidChange(testFiles)
326+
}
331327
}
332328

333329
/// Wrapper around a workspace that isn't being retained.

Tests/BuildSystemIntegrationTests/BuildSystemManagerTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,6 @@ private actor BSMDelegate: BuildSystemManagerDelegate {
406406
func buildTargetsChanged(_ changes: [BuildTargetEvent]?) async {}
407407

408408
nonisolated func logMessageToIndexLog(taskID: BuildSystemIntegration.IndexTaskID, message: String) {}
409+
410+
func sourceFilesDidChange() async {}
409411
}

0 commit comments

Comments
 (0)