@@ -711,18 +711,13 @@ package final actor SemanticIndexManager {
711
711
// sort files to get deterministic indexing order
712
712
. sorted ( by: { $0. file. sourceFile. stringValue < $1. file. sourceFile. stringValue } )
713
713
714
- // The number of index tasks that don't currently have an in-progress task associated with it.
715
- // The denominator in the index progress should get incremented by this amount.
716
- // We don't want to increment the denominator for tasks that already have an index in progress.
717
- var newIndexTasks = 0
718
714
var alreadyScheduledTasks : Set < FileToIndex > = [ ]
719
715
for file in filesToIndex {
720
716
let inProgress = inProgressIndexTasks [ file. file]
721
717
722
718
let shouldScheduleIndexing : Bool
723
719
switch inProgress? . state {
724
720
case nil :
725
- newIndexTasks += 1
726
721
shouldScheduleIndexing = true
727
722
case . creatingIndexTask, . waitingForPreparation:
728
723
// We already have a task that indexes the file but hasn't started preparation yet. Indexing the file again
@@ -739,18 +734,11 @@ package final actor SemanticIndexManager {
739
734
}
740
735
}
741
736
if shouldScheduleIndexing {
742
- inProgressIndexTasks [ file. file] = InProgressIndexStore (
743
- state: . creatingIndexTask,
744
- fileModificationDate: file. fileModificationDate
745
- )
737
+
746
738
} else {
747
739
alreadyScheduledTasks. insert ( file. file)
748
-
749
740
}
750
741
}
751
- if newIndexTasks > 0 {
752
- indexTasksWereScheduled ( newIndexTasks)
753
- }
754
742
filesToIndex = filesToIndex. filter { !alreadyScheduledTasks. contains ( $0. file) }
755
743
756
744
if filesToIndex. isEmpty {
@@ -764,7 +752,12 @@ package final actor SemanticIndexManager {
764
752
// to index the low-level targets ASAP.
765
753
var filesByTarget : [ BuildTargetIdentifier : [ ( FileToIndex ) ] ] = [ : ]
766
754
767
- for fileToIndex in filesToIndex. map ( \. file) {
755
+ // The number of index tasks that don't currently have an in-progress task associated with it.
756
+ // The denominator in the index progress should get incremented by this amount.
757
+ // We don't want to increment the denominator for tasks that already have an index in progress.
758
+ var newIndexTasks = 0
759
+
760
+ for (fileToIndex, fileModificationDate) in filesToIndex {
768
761
guard let target = await buildSystemManager. canonicalTarget ( for: fileToIndex. mainFile) else {
769
762
logger. error (
770
763
" Not indexing \( fileToIndex. forLogging) because the target could not be determined "
@@ -777,8 +770,21 @@ package final actor SemanticIndexManager {
777
770
continue
778
771
}
779
772
773
+ if inProgressIndexTasks [ fileToIndex] == nil {
774
+ // If `inProgressIndexTasks[fileToIndex]` is not `nil`, this new index task is replacing another index task.
775
+ // We are thus not indexing a new file and thus shouldn't increment the denominator of the indexing status.
776
+ newIndexTasks += 1
777
+ }
778
+ inProgressIndexTasks [ fileToIndex] = InProgressIndexStore (
779
+ state: . creatingIndexTask,
780
+ fileModificationDate: fileModificationDate
781
+ )
782
+
780
783
filesByTarget [ target, default: [ ] ] . append ( fileToIndex)
781
784
}
785
+ if newIndexTasks > 0 {
786
+ indexTasksWereScheduled ( newIndexTasks)
787
+ }
782
788
783
789
// The targets sorted in reverse topological order, low-level targets before high-level targets. If topological
784
790
// sorting fails, sorted in another deterministic way where the actual order doesn't matter.
0 commit comments