@@ -711,18 +711,13 @@ package final actor SemanticIndexManager {
711711 // sort files to get deterministic indexing order
712712 . sorted ( by: { $0. file. sourceFile. stringValue < $1. file. sourceFile. stringValue } )
713713
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
718714 var alreadyScheduledTasks : Set < FileToIndex > = [ ]
719715 for file in filesToIndex {
720716 let inProgress = inProgressIndexTasks [ file. file]
721717
722718 let shouldScheduleIndexing : Bool
723719 switch inProgress? . state {
724720 case nil :
725- newIndexTasks += 1
726721 shouldScheduleIndexing = true
727722 case . creatingIndexTask, . waitingForPreparation:
728723 // 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 {
739734 }
740735 }
741736 if shouldScheduleIndexing {
742- inProgressIndexTasks [ file. file] = InProgressIndexStore (
743- state: . creatingIndexTask,
744- fileModificationDate: file. fileModificationDate
745- )
737+
746738 } else {
747739 alreadyScheduledTasks. insert ( file. file)
748-
749740 }
750741 }
751- if newIndexTasks > 0 {
752- indexTasksWereScheduled ( newIndexTasks)
753- }
754742 filesToIndex = filesToIndex. filter { !alreadyScheduledTasks. contains ( $0. file) }
755743
756744 if filesToIndex. isEmpty {
@@ -764,7 +752,12 @@ package final actor SemanticIndexManager {
764752 // to index the low-level targets ASAP.
765753 var filesByTarget : [ BuildTargetIdentifier : [ ( FileToIndex ) ] ] = [ : ]
766754
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 {
768761 guard let target = await buildSystemManager. canonicalTarget ( for: fileToIndex. mainFile) else {
769762 logger. error (
770763 " Not indexing \( fileToIndex. forLogging) because the target could not be determined "
@@ -777,8 +770,21 @@ package final actor SemanticIndexManager {
777770 continue
778771 }
779772
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+
780783 filesByTarget [ target, default: [ ] ] . append ( fileToIndex)
781784 }
785+ if newIndexTasks > 0 {
786+ indexTasksWereScheduled ( newIndexTasks)
787+ }
782788
783789 // The targets sorted in reverse topological order, low-level targets before high-level targets. If topological
784790 // sorting fails, sorted in another deterministic way where the actual order doesn't matter.
0 commit comments