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:
Alex Hoppen
2024-09-09 11:49:54 -07:00
parent 33e955ab6c
commit 4d1fa7a7ee
9 changed files with 36 additions and 35 deletions

View File

@@ -137,8 +137,10 @@ package protocol BuildSystem: AnyObject, Sendable {
/// Return the list of targets and run destinations that the given document can be built for.
func configuredTargets(for document: DocumentURI) async -> [ConfiguredTarget]
/// Re-generate the build graph.
func generateBuildGraph() async throws
/// 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