@@ -18,6 +18,14 @@ import SemanticIndex
1818/// Listens for index status updates from `SemanticIndexManagers`. From that information, it manages a
1919/// `WorkDoneProgress` that communicates the index progress to the editor.
2020actor IndexProgressManager {
21+ /// A queue on which `indexTaskWasQueued` and `indexStatusDidChange` are handled.
22+ ///
23+ /// This allows the two functions two be `nonisolated` (and eg. the caller of `indexStatusDidChange` doesn't have to
24+ /// wait for the work done progress to be updated) while still guaranteeing that there is only one
25+ /// `indexStatusDidChangeImpl` running at a time, preventing race conditions that would cause two
26+ /// `WorkDoneProgressManager`s to be created.
27+ private let queue = AsyncQueue < Serial > ( )
28+
2129 /// The `SourceKitLSPServer` for which this manages the index progress. It gathers all `SemanticIndexManagers` from
2230 /// the workspaces in the `SourceKitLSPServer`.
2331 private weak var sourceKitLSPServer : SourceKitLSPServer ?
@@ -42,7 +50,7 @@ actor IndexProgressManager {
4250
4351 /// Called when a new file is scheduled to be indexed. Increments the target index count, eg. the 3 in `1/3`.
4452 nonisolated func indexTasksWereScheduled( count: Int ) {
45- Task {
53+ queue . async {
4654 await self . indexTasksWereScheduledImpl ( count: count)
4755 }
4856 }
@@ -54,7 +62,7 @@ actor IndexProgressManager {
5462
5563 /// Called when a `SemanticIndexManager` finishes indexing a file. Adjusts the done index count, eg. the 1 in `1/3`.
5664 nonisolated func indexStatusDidChange( ) {
57- Task {
65+ queue . async {
5866 await self . indexStatusDidChangeImpl ( )
5967 }
6068 }
0 commit comments