@@ -91,6 +91,13 @@ private struct InProgressIndexStore {
9191 var fileModificationDate : Date ?
9292}
9393
94+ /// The information that's needed to index a file within a given target.
95+ package struct FileIndexInfo : Sendable , Hashable {
96+ package let file : FileToIndex
97+ package let target : BuildTargetIdentifier
98+ package let outputPath : OutputPath
99+ }
100+
94101/// Status of document indexing / target preparation in `inProgressIndexAndPreparationTasks`.
95102package enum IndexTaskStatus : Comparable {
96103 case scheduled
@@ -722,16 +729,18 @@ package final actor SemanticIndexManager {
722729 }
723730 }
724731
725- /// Update the index store for the given files, assuming that their targets have already been prepared.
732+ /// Update the index store for the given files, assuming that their targets has already been prepared.
726733 private func updateIndexStore(
727- for filesAndTargets: [ FileIndexInfo ] ,
734+ for fileAndOutputPaths: [ FileAndOutputPath ] ,
735+ target: BuildTargetIdentifier ,
728736 indexFilesWithUpToDateUnit: Bool ,
729737 preparationTaskID: UUID ,
730738 priority: TaskPriority ?
731739 ) async {
732740 let taskDescription = AnyIndexTaskDescription (
733741 UpdateIndexStoreTaskDescription (
734- filesToIndex: filesAndTargets,
742+ filesToIndex: fileAndOutputPaths,
743+ target: target,
735744 buildServerManager: self . buildServerManager,
736745 index: index,
737746 indexStoreUpToDateTracker: indexStoreUpToDateTracker,
@@ -747,7 +756,12 @@ package final actor SemanticIndexManager {
747756 self . indexProgressStatusDidChange ( )
748757 return
749758 }
750- for fileAndTarget in filesAndTargets {
759+ for fileAndOutputPath in fileAndOutputPaths {
760+ let fileAndTarget = FileIndexInfo (
761+ file: fileAndOutputPath. file,
762+ target: target,
763+ outputPath: fileAndOutputPath. outputPath
764+ )
751765 switch self . inProgressIndexTasks [ fileAndTarget] ? . state {
752766 case . updatingIndexStore( let registeredTask, _) :
753767 if registeredTask == OpaqueQueuedIndexTask ( task) {
@@ -763,7 +777,12 @@ package final actor SemanticIndexManager {
763777 }
764778 self . indexProgressStatusDidChange ( )
765779 }
766- for fileAndTarget in filesAndTargets {
780+ for fileAndOutputPath in fileAndOutputPaths {
781+ let fileAndTarget = FileIndexInfo (
782+ file: fileAndOutputPath. file,
783+ target: target,
784+ outputPath: fileAndOutputPath. outputPath
785+ )
767786 switch inProgressIndexTasks [ fileAndTarget] ? . state {
768787 case . waitingForPreparation( preparationTaskID, let indexTask) , . preparing( preparationTaskID, let indexTask) :
769788 inProgressIndexTasks [ fileAndTarget] ? . state = . updatingIndexStore(
@@ -938,8 +957,18 @@ package final actor SemanticIndexManager {
938957 // (https://github.com/swiftlang/sourcekit-lsp/issues/1268)
939958 for fileBatch in filesByTarget [ target] !. partition ( intoBatchesOfSize: 1 ) {
940959 taskGroup. addTask {
960+ let fileAndOutputPaths : [ FileAndOutputPath ] = fileBatch. compactMap {
961+ guard $0. target == target else {
962+ logger. fault (
963+ " FileIndexInfo refers to different target than should be indexed \( $0. target. forLogging) vs \( target. forLogging) "
964+ )
965+ return nil
966+ }
967+ return FileAndOutputPath ( file: $0. file, outputPath: $0. outputPath)
968+ }
941969 await self . updateIndexStore (
942- for: fileBatch,
970+ for: fileAndOutputPaths,
971+ target: target,
943972 indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
944973 preparationTaskID: preparationTaskID,
945974 priority: priority
0 commit comments