@@ -91,6 +91,13 @@ private struct InProgressIndexStore {
91
91
var fileModificationDate : Date ?
92
92
}
93
93
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
+
94
101
/// Status of document indexing / target preparation in `inProgressIndexAndPreparationTasks`.
95
102
package enum IndexTaskStatus : Comparable {
96
103
case scheduled
@@ -722,16 +729,18 @@ package final actor SemanticIndexManager {
722
729
}
723
730
}
724
731
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.
726
733
private func updateIndexStore(
727
- for filesAndTargets: [ FileIndexInfo ] ,
734
+ for fileAndOutputPaths: [ FileAndOutputPath ] ,
735
+ target: BuildTargetIdentifier ,
728
736
indexFilesWithUpToDateUnit: Bool ,
729
737
preparationTaskID: UUID ,
730
738
priority: TaskPriority ?
731
739
) async {
732
740
let taskDescription = AnyIndexTaskDescription (
733
741
UpdateIndexStoreTaskDescription (
734
- filesToIndex: filesAndTargets,
742
+ filesToIndex: fileAndOutputPaths,
743
+ target: target,
735
744
buildServerManager: self . buildServerManager,
736
745
index: index,
737
746
indexStoreUpToDateTracker: indexStoreUpToDateTracker,
@@ -747,7 +756,12 @@ package final actor SemanticIndexManager {
747
756
self . indexProgressStatusDidChange ( )
748
757
return
749
758
}
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
+ )
751
765
switch self . inProgressIndexTasks [ fileAndTarget] ? . state {
752
766
case . updatingIndexStore( let registeredTask, _) :
753
767
if registeredTask == OpaqueQueuedIndexTask ( task) {
@@ -763,7 +777,12 @@ package final actor SemanticIndexManager {
763
777
}
764
778
self . indexProgressStatusDidChange ( )
765
779
}
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
+ )
767
786
switch inProgressIndexTasks [ fileAndTarget] ? . state {
768
787
case . waitingForPreparation( preparationTaskID, let indexTask) , . preparing( preparationTaskID, let indexTask) :
769
788
inProgressIndexTasks [ fileAndTarget] ? . state = . updatingIndexStore(
@@ -938,8 +957,18 @@ package final actor SemanticIndexManager {
938
957
// (https://github.com/swiftlang/sourcekit-lsp/issues/1268)
939
958
for fileBatch in filesByTarget [ target] !. partition ( intoBatchesOfSize: 1 ) {
940
959
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
+ }
941
969
await self . updateIndexStore (
942
- for: fileBatch,
970
+ for: fileAndOutputPaths,
971
+ target: target,
943
972
indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
944
973
preparationTaskID: preparationTaskID,
945
974
priority: priority
0 commit comments