Skip to content

Commit ba35f6d

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 4db294b commit ba35f6d

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 {
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
///
@@ -431,11 +431,6 @@ package final actor SemanticIndexManager {
431431
if !indexFilesWithUpToDateUnits, await indexStoreUpToDateTracker.isUpToDate($0) {
432432
return false
433433
}
434-
if case .waitingForPreparation = inProgressIndexTasks[$0] {
435-
// We haven't started preparing the file yet. Scheduling a new index operation for it won't produce any
436-
// more recent results.
437-
return false
438-
}
439434
return true
440435
}.compactMap { (uri) -> FileToIndex? in
441436
if sourceFiles.contains(uri) {
@@ -462,6 +457,14 @@ package final actor SemanticIndexManager {
462457
}
463458
return .headerFile(header: uri, mainFile: mainFile)
464459
}
460+
.filter {
461+
switch inProgressIndexTasks[$0] {
462+
case .waitingForPreparation:
463+
return false
464+
default:
465+
return true
466+
}
467+
}
465468
return filesToReIndex
466469
}
467470

@@ -638,14 +641,14 @@ package final actor SemanticIndexManager {
638641
return
639642
}
640643
for fileAndTarget in filesAndTargets {
641-
switch self.inProgressIndexTasks[fileAndTarget.file.sourceFile] {
644+
switch self.inProgressIndexTasks[fileAndTarget.file] {
642645
case .updatingIndexStore(let registeredTask, _):
643646
if registeredTask == OpaqueQueuedIndexTask(task) {
644-
self.inProgressIndexTasks[fileAndTarget.file.sourceFile] = nil
647+
self.inProgressIndexTasks[fileAndTarget.file] = nil
645648
}
646649
case .waitingForPreparation(let registeredTask, _), .preparing(let registeredTask, _):
647650
if registeredTask == preparationTaskID {
648-
self.inProgressIndexTasks[fileAndTarget.file.sourceFile] = nil
651+
self.inProgressIndexTasks[fileAndTarget.file] = nil
649652
}
650653
case nil:
651654
break
@@ -654,9 +657,9 @@ package final actor SemanticIndexManager {
654657
self.indexProgressStatusDidChange()
655658
}
656659
for fileAndTarget in filesAndTargets {
657-
switch inProgressIndexTasks[fileAndTarget.file.sourceFile] {
660+
switch inProgressIndexTasks[fileAndTarget.file] {
658661
case .waitingForPreparation(preparationTaskID, let indexTask), .preparing(preparationTaskID, let indexTask):
659-
inProgressIndexTasks[fileAndTarget.file.sourceFile] = .updatingIndexStore(
662+
inProgressIndexTasks[fileAndTarget.file] = .updatingIndexStore(
660663
updateIndexStoreTask: OpaqueQueuedIndexTask(updateIndexTask),
661664
indexTask: indexTask
662665
)
@@ -742,9 +745,9 @@ package final actor SemanticIndexManager {
742745
if case .executing = newState {
743746
for file in filesToIndex {
744747
if case .waitingForPreparation(preparationTaskID: preparationTaskID, indexTask: let indexTask) =
745-
self.inProgressIndexTasks[file.sourceFile]
748+
self.inProgressIndexTasks[file]
746749
{
747-
self.inProgressIndexTasks[file.sourceFile] = .preparing(
750+
self.inProgressIndexTasks[file] = .preparing(
748751
preparationTaskID: preparationTaskID,
749752
indexTask: indexTask
750753
)
@@ -778,14 +781,14 @@ package final actor SemanticIndexManager {
778781
// The number of index tasks that don't currently have an in-progress task associated with it.
779782
// The denominator in the index progress should get incremented by this amount.
780783
// We don't want to increment the denominator for tasks that already have an index in progress.
781-
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0.sourceFile] == nil }.count
784+
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0] == nil }.count
782785
for file in filesToIndex {
783786
// The state of `inProgressIndexTasks` will get pushed on from `updateIndexStore`.
784787
// The updates to `inProgressIndexTasks` from `updateIndexStore` cannot race with setting it to
785788
// `.waitingForPreparation` here because we don't have an `await` call between the creation of `indexTask` and
786789
// this loop, so we still have exclusive access to the `SemanticIndexManager` actor and hence `updateIndexStore`
787790
// can't execute until we have set all index statuses to `.waitingForPreparation`.
788-
inProgressIndexTasks[file.sourceFile] = .waitingForPreparation(
791+
inProgressIndexTasks[file] = .waitingForPreparation(
789792
preparationTaskID: preparationTaskID,
790793
indexTask: indexTask
791794
)

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)