Skip to content

Commit 3787ca8

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 c433cf6 commit 3787ca8

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

@@ -626,14 +629,14 @@ package final actor SemanticIndexManager {
626629
return
627630
}
628631
for fileAndTarget in filesAndTargets {
629-
switch self.inProgressIndexTasks[fileAndTarget.file.sourceFile] {
632+
switch self.inProgressIndexTasks[fileAndTarget.file] {
630633
case .updatingIndexStore(let registeredTask, _):
631634
if registeredTask == OpaqueQueuedIndexTask(task) {
632-
self.inProgressIndexTasks[fileAndTarget.file.sourceFile] = nil
635+
self.inProgressIndexTasks[fileAndTarget.file] = nil
633636
}
634637
case .waitingForPreparation(let registeredTask, _), .preparing(let registeredTask, _):
635638
if registeredTask == preparationTaskID {
636-
self.inProgressIndexTasks[fileAndTarget.file.sourceFile] = nil
639+
self.inProgressIndexTasks[fileAndTarget.file] = nil
637640
}
638641
case nil:
639642
break
@@ -642,9 +645,9 @@ package final actor SemanticIndexManager {
642645
self.indexProgressStatusDidChange()
643646
}
644647
for fileAndTarget in filesAndTargets {
645-
switch inProgressIndexTasks[fileAndTarget.file.sourceFile] {
648+
switch inProgressIndexTasks[fileAndTarget.file] {
646649
case .waitingForPreparation(preparationTaskID, let indexTask), .preparing(preparationTaskID, let indexTask):
647-
inProgressIndexTasks[fileAndTarget.file.sourceFile] = .updatingIndexStore(
650+
inProgressIndexTasks[fileAndTarget.file] = .updatingIndexStore(
648651
updateIndexStoreTask: OpaqueQueuedIndexTask(updateIndexTask),
649652
indexTask: indexTask
650653
)
@@ -730,9 +733,9 @@ package final actor SemanticIndexManager {
730733
if case .executing = newState {
731734
for file in filesToIndex {
732735
if case .waitingForPreparation(preparationTaskID: preparationTaskID, indexTask: let indexTask) =
733-
self.inProgressIndexTasks[file.sourceFile]
736+
self.inProgressIndexTasks[file]
734737
{
735-
self.inProgressIndexTasks[file.sourceFile] = .preparing(
738+
self.inProgressIndexTasks[file] = .preparing(
736739
preparationTaskID: preparationTaskID,
737740
indexTask: indexTask
738741
)
@@ -766,14 +769,14 @@ package final actor SemanticIndexManager {
766769
// The number of index tasks that don't currently have an in-progress task associated with it.
767770
// The denominator in the index progress should get incremented by this amount.
768771
// We don't want to increment the denominator for tasks that already have an index in progress.
769-
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0.sourceFile] == nil }.count
772+
let newIndexTasks = filesToIndex.filter { inProgressIndexTasks[$0] == nil }.count
770773
for file in filesToIndex {
771774
// The state of `inProgressIndexTasks` will get pushed on from `updateIndexStore`.
772775
// The updates to `inProgressIndexTasks` from `updateIndexStore` cannot race with setting it to
773776
// `.waitingForPreparation` here because we don't have an `await` call between the creation of `indexTask` and
774777
// this loop, so we still have exclusive access to the `SemanticIndexManager` actor and hence `updateIndexStore`
775778
// can't execute until we have set all index statuses to `.waitingForPreparation`.
776-
inProgressIndexTasks[file.sourceFile] = .waitingForPreparation(
779+
inProgressIndexTasks[file] = .waitingForPreparation(
777780
preparationTaskID: preparationTaskID,
778781
indexTask: indexTask
779782
)

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)