@@ -18,6 +18,14 @@ import SemanticIndex
18
18
/// Listens for index status updates from `SemanticIndexManagers`. From that information, it manages a
19
19
/// `WorkDoneProgress` that communicates the index progress to the editor.
20
20
actor 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
+
21
29
/// The `SourceKitLSPServer` for which this manages the index progress. It gathers all `SemanticIndexManagers` from
22
30
/// the workspaces in the `SourceKitLSPServer`.
23
31
private weak var sourceKitLSPServer : SourceKitLSPServer ?
@@ -42,7 +50,7 @@ actor IndexProgressManager {
42
50
43
51
/// Called when a new file is scheduled to be indexed. Increments the target index count, eg. the 3 in `1/3`.
44
52
nonisolated func indexTasksWereScheduled( count: Int ) {
45
- Task {
53
+ queue . async {
46
54
await self . indexTasksWereScheduledImpl ( count: count)
47
55
}
48
56
}
@@ -54,7 +62,7 @@ actor IndexProgressManager {
54
62
55
63
/// Called when a `SemanticIndexManager` finishes indexing a file. Adjusts the done index count, eg. the 1 in `1/3`.
56
64
nonisolated func indexStatusDidChange( ) {
57
- Task {
65
+ queue . async {
58
66
await self . indexStatusDidChangeImpl ( )
59
67
}
60
68
}
0 commit comments