mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
Fix a race condition that could cause the build graph to not be generated when doing initial background indexing
We were making the initial `generateBuildGraph` call in `SourceKitLSPServer` from a `Task`. This means that `generateBuildGraph` could be executed after `waitForUpToDateBuildGraph` was called by `SemanticIndexManager`. Thus `waitForUpToDateBuildGraph` returned immediately and no files were background indexed. Make `generateBuildGraph` immediately schedule a package reload for SwiftPM build systems instead of doing the hop through a `Task`, fixing the race condition. rdar://135551812
This commit is contained in:
@@ -365,10 +365,11 @@ package actor SwiftPMBuildSystem {
|
||||
extension SwiftPMBuildSystem {
|
||||
/// (Re-)load the package settings by parsing the manifest and resolving all the targets and
|
||||
/// dependencies.
|
||||
package func reloadPackage() async throws {
|
||||
try await packageLoadingQueue.asyncThrowing {
|
||||
@discardableResult
|
||||
package func schedulePackageReload() -> Task<Void, Swift.Error> {
|
||||
return packageLoadingQueue.asyncThrowing {
|
||||
try await self.reloadPackageImpl()
|
||||
}.valuePropagatingCancellation
|
||||
}
|
||||
}
|
||||
|
||||
/// - Important: Must only be called on `packageLoadingQueue`.
|
||||
@@ -549,8 +550,8 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuildSystem {
|
||||
return []
|
||||
}
|
||||
|
||||
package func generateBuildGraph() async throws {
|
||||
try await self.reloadPackage()
|
||||
package func scheduleBuildGraphGeneration() async throws {
|
||||
self.schedulePackageReload()
|
||||
}
|
||||
|
||||
package func waitForUpToDateBuildGraph() async {
|
||||
@@ -743,7 +744,7 @@ extension SwiftPMBuildSystem: BuildSystemIntegration.BuildSystem {
|
||||
if events.contains(where: { self.fileEventShouldTriggerPackageReload(event: $0) }) {
|
||||
logger.log("Reloading package because of file change")
|
||||
await orLog("Reloading package") {
|
||||
try await self.reloadPackage()
|
||||
try await self.schedulePackageReload().value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user