Skip to content

Commit 0cb7c82

Browse files
committed
Use FileToIndex as the key of inProgressIndexTasks
Indexing a header via a main file and indexing the main file itself are two different index tasks that update the `indexStoreUpToDateTracker` in different ways. We should thus consider them differently in `inProgressIndexTasks` as well.
1 parent 86be2a4 commit 0cb7c82

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ package enum IndexTaskStatus: Comparable {
9696
package enum IndexProgressStatus: Sendable, Equatable {
9797
case preparingFileForEditorFunctionality
9898
case schedulingIndexing
99-
case indexing(preparationTasks: [BuildTargetIdentifier: IndexTaskStatus], indexTasks: [DocumentURI: IndexTaskStatus])
99+
case indexing(preparationTasks: [BuildTargetIdentifier: IndexTaskStatus], indexTasks: [FileToIndex: IndexTaskStatus])
100100
case upToDate
101101

102102
package func merging(with other: IndexProgressStatus) -> IndexProgressStatus {
@@ -182,7 +182,7 @@ package final actor SemanticIndexManager {
182182
/// store update task to be scheduled in the task scheduler or which currently have an index store update running.
183183
///
184184
/// After the file is indexed, it is removed from this dictionary.
185-
private var inProgressIndexTasks: [DocumentURI: InProgressIndexStore] = [:]
185+
private var inProgressIndexTasks: [FileToIndex: InProgressIndexStore] = [:]
186186

187187
/// The currently running task that prepares a document for editor functionality.
188188
///
@@ -420,11 +420,6 @@ package final actor SemanticIndexManager {
420420
if !indexFilesWithUpToDateUnits, await indexStoreUpToDateTracker.isUpToDate($0) {
421421
return false
422422
}
423-
if case .waitingForPreparation = inProgressIndexTasks[$0] {
424-
// We haven't started preparing the file yet. Scheduling a new index operation for it won't produce any
425-
// more recent results.
426-
return false
427-
}
428423
return true
429424
}.compactMap { (uri) -> FileToIndex? in
430425
if sourceFiles.contains(uri) {
@@ -451,6 +446,14 @@ package final actor SemanticIndexManager {
451446
}
452447
return .headerFile(header: uri, mainFile: mainFile)
453448
}
449+
.filter {
450+
switch inProgressIndexTasks[$0] {
451+
case .waitingForPreparation:
452+
return false
453+
default:
454+
return true
455+
}
456+
}
454457
return filesToReIndex
455458
}
456459

@@ -627,14 +630,14 @@ package final actor SemanticIndexManager {
627630
return
628631
}
629632
for fileAndTarget in filesAndTargets {
630-
switch self.inProgressIndexTasks[fileAndTarget.file.sourceFile] {
633+
switch self.inProgressIndexTasks[fileAndTarget.file] {
631634
case .updatingIndexStore(let registeredTask, _):
632635
if registeredTask == OpaqueQueuedIndexTask(task) {
633-
self.inProgressIndexTasks[fileAndTarget.file.sourceFile] = nil
636+
self.inProgressIndexTasks[fileAndTarget.file] = nil
634637
}
635638
case .waitingForPreparation(let registeredTask, _), .preparing(let registeredTask, _):
636639
if registeredTask == preparationTaskID {
637-
self.inProgressIndexTasks[fileAndTarget.file.sourceFile] = nil
640+
self.inProgressIndexTasks[fileAndTarget.file] = nil
638641
}
639642
case nil:
640643
break
@@ -643,9 +646,9 @@ package final actor SemanticIndexManager {
643646
self.indexProgressStatusDidChange()
644647
}
645648
for fileAndTarget in filesAndTargets {
646-
switch inProgressIndexTasks[fileAndTarget.file.sourceFile] {
649+
switch inProgressIndexTasks[fileAndTarget.file] {
647650
case .waitingForPreparation(preparationTaskID, let indexTask), .preparing(preparationTaskID, let indexTask):
648-
inProgressIndexTasks[fileAndTarget.file.sourceFile] = .updatingIndexStore(
651+
inProgressIndexTasks[fileAndTarget.file] = .updatingIndexStore(
649652
updateIndexStoreTask: OpaqueQueuedIndexTask(updateIndexTask),
650653
indexTask: indexTask
651654
)
@@ -731,9 +734,9 @@ package final actor SemanticIndexManager {
731734
if case .executing = newState {
732735
for file in filesToIndex {
733736
if case .waitingForPreparation(preparationTaskID: preparationTaskID, indexTask: let indexTask) =
734-
self.inProgressIndexTasks[file.sourceFile]
737+
self.inProgressIndexTasks[file]
735738
{
736-
self.inProgressIndexTasks[file.sourceFile] = .preparing(
739+
self.inProgressIndexTasks[file] = .preparing(
737740
preparationTaskID: preparationTaskID,
738741
indexTask: indexTask
739742
)
@@ -767,14 +770,14 @@ package final actor SemanticIndexManager {
767770
// The number of index tasks that don't currently have an in-progress task associated with it.
768771
// The denominator in the index progress should get incremented by this amount.
769772
// We don't want to increment the denominator for tasks that already have an index in progress.
770-
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0.sourceFile] == nil }.count
773+
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0] == nil }.count
771774
for file in filesToIndex {
772775
// The state of `inProgressIndexTasks` will get pushed on from `updateIndexStore`.
773776
// The updates to `inProgressIndexTasks` from `updateIndexStore` cannot race with setting it to
774777
// `.waitingForPreparation` here because we don't have an `await` call between the creation of `indexTask` and
775778
// this loop, so we still have exclusive access to the `SemanticIndexManager` actor and hence `updateIndexStore`
776779
// can't execute until we have set all index statuses to `.waitingForPreparation`.
777-
inProgressIndexTasks[file.sourceFile] = .waitingForPreparation(
780+
inProgressIndexTasks[file] = .waitingForPreparation(
778781
preparationTaskID: preparationTaskID,
779782
indexTask: indexTask
780783
)

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import struct TSCBasic.ProcessResult
4242

4343
private let updateIndexStoreIDForLogging = AtomicUInt32(initialValue: 1)
4444

45-
package enum FileToIndex: CustomLogStringConvertible {
45+
package enum FileToIndex: CustomLogStringConvertible, Hashable {
4646
/// A non-header file
4747
case indexableFile(DocumentURI)
4848

0 commit comments

Comments
 (0)