Skip to content

Commit bc1cd2c

Browse files
authored
Merge pull request #1332 from ahoppen/review-comments-1322-1326
Address review comments to #1322 and #1326
2 parents 927056b + 8f8ff45 commit bc1cd2c

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ public final actor SemanticIndexManager {
264264
if let dependentTargets = await buildSystemManager.targets(dependingOn: targets) {
265265
await preparationUpToDateStatus.markOutOfDate(dependentTargets)
266266
} else {
267-
// We couldn't determine which targets depend on the modified targets. Be conservative and assume all of them do.
268-
await indexStoreUpToDateStatus.markOutOfDate(changedFiles)
269-
270267
await preparationUpToDateStatus.markAllOutOfDate()
271268
// `markAllOutOfDate` only marks targets out-of-date that have been indexed before. Also mark all targets with
272269
// in-progress preparation out of date. So we don't get into the following situation, which would result in an
@@ -524,17 +521,22 @@ public final actor SemanticIndexManager {
524521
indexTasks.append(indexTask)
525522

526523
let filesToIndex = targetsBatch.flatMap({ filesByTarget[$0]! })
524+
// The number of index tasks that don't currently have an in-progress task associated with it.
525+
// The denominator in the index progress should get incremented by this amount.
526+
// We don't want to increment the denominator for tasks that already have an index in progress.
527+
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0.sourceFile] == nil }.count
527528
for file in filesToIndex {
528-
// indexStatus will get set to `.upToDate` by `updateIndexStore`. Setting it to `.upToDate` cannot race with
529-
// setting it to `.scheduled` because we don't have an `await` call between the creation of `indexTask` and
529+
// The state of `inProgressIndexTasks` will get pushed on from `updateIndexStore`.
530+
// The updates to `inProgressIndexTasks` from `updateIndexStore` cannot race with setting it to
531+
// `.waitingForPreparation` here because we don't have an `await` call between the creation of `indexTask` and
530532
// this loop, so we still have exclusive access to the `SemanticIndexManager` actor and hence `updateIndexStore`
531-
// can't execute until we have set all index statuses to `.scheduled`.
533+
// can't execute until we have set all index statuses to `.waitingForPreparation`.
532534
inProgressIndexTasks[file.sourceFile] = .waitingForPreparation(
533535
preparationTaskID: preparationTaskID,
534536
indexTask: indexTask
535537
)
536538
}
537-
indexTasksWereScheduled(filesToIndex.count)
539+
indexTasksWereScheduled(newIndexTasks)
538540
}
539541
let indexTasksImmutable = indexTasks
540542

Sources/SourceKitLSP/IndexProgressManager.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ actor IndexProgressManager {
3939
///
4040
/// The number of outstanding tasks is determined from the `scheduled` and `executing` tasks in all the
4141
/// `SemanticIndexManager`s.
42+
///
43+
/// Note that the `queuedIndexTasks` might exceed the number of files in the project, eg. in the following scenario:
44+
/// - Schedule indexing of A.swift and B.swift -> 0 / 2
45+
/// - Indexing of A.swift finishes -> 1 / 2
46+
/// - A.swift is modified and should be indexed again -> 1 / 3
47+
/// - B.swift finishes indexing -> 2 / 3
48+
/// - A.swift finishes indexing for the second time -> 3 / 3 -> Status disappears
4249
private var queuedIndexTasks = 0
4350

4451
/// While there are ongoing index tasks, a `WorkDoneProgressManager` that displays the work done progress.

0 commit comments

Comments
 (0)