@@ -928,7 +928,13 @@ package final actor SemanticIndexManager {
928
928
// (https://github.com/swiftlang/sourcekit-lsp/issues/1262)
929
929
for targetsBatch in sortedTargets. partition ( intoBatchesOfSize: 1 ) {
930
930
let preparationTaskID = UUID ( )
931
- let filesToIndex = targetsBatch. flatMap ( { filesByTarget [ $0] ! } )
931
+ let filesToIndex = targetsBatch. flatMap { ( target) -> [ FileIndexInfo ] in
932
+ guard let files = filesByTarget [ target] else {
933
+ logger. fault ( " Unexpectedly found no files for target in target batch " )
934
+ return [ ]
935
+ }
936
+ return files
937
+ }
932
938
933
939
// First schedule preparation of the targets. We schedule the preparation outside of `indexTask` so that we
934
940
// deterministically prepare targets in the topological order for indexing. If we triggered preparation inside the
@@ -957,36 +963,36 @@ package final actor SemanticIndexManager {
957
963
958
964
// And after preparation is done, index the files in the targets.
959
965
await withTaskGroup ( of: Void . self) { taskGroup in
960
- for target in targetsBatch {
961
- var filesByLanguage : [ Language : [ FileIndexInfo ] ] = [ : ]
962
- for fileInfo in filesByTarget [ target] ! {
963
- filesByLanguage [ fileInfo . language , default : [ ] ] . append ( fileInfo )
966
+ let fileInfos = targetsBatch. flatMap { ( target ) -> [ FileIndexInfo ] in
967
+ guard let files = filesByTarget [ target ] else {
968
+ logger . fault ( " Unexpectedly found no files for target in target batch " )
969
+ return [ ]
964
970
}
965
- for (language, fileInfos) in filesByLanguage {
966
- // TODO: Once swiftc supports indexing of multiple files in a single invocation, increase the batch size to
967
- // allow it to share AST builds between multiple files within a target.
968
- // (https://github.com/swiftlang/sourcekit-lsp/issues/1268)
969
- for fileBatch in fileInfos. partition ( intoBatchesOfSize: 1 ) {
970
- taskGroup. addTask {
971
- let fileAndOutputPaths : [ FileAndOutputPath ] = fileBatch. compactMap {
972
- guard $0. target == target else {
973
- logger. fault (
974
- " FileIndexInfo refers to different target than should be indexed \( $0. target. forLogging) vs \( target. forLogging) "
975
- )
976
- return nil
977
- }
978
- return FileAndOutputPath ( file: $0. file, outputPath: $0. outputPath)
979
- }
980
- await self . updateIndexStore (
981
- for: fileAndOutputPaths,
982
- target: target,
983
- language: language,
984
- indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
985
- preparationTaskID: preparationTaskID,
986
- priority: priority
971
+ return files
972
+ }
973
+ let batches = await UpdateIndexStoreTaskDescription . batches (
974
+ toIndex: fileInfos,
975
+ buildServerManager: buildServerManager
976
+ )
977
+ for (target, language, fileBatch) in batches {
978
+ taskGroup. addTask {
979
+ let fileAndOutputPaths : [ FileAndOutputPath ] = fileBatch. compactMap {
980
+ guard $0. target == target else {
981
+ logger. fault (
982
+ " FileIndexInfo refers to different target than should be indexed: \( $0. target. forLogging) vs \( target. forLogging) "
987
983
)
984
+ return nil
988
985
}
986
+ return FileAndOutputPath ( file: $0. file, outputPath: $0. outputPath)
989
987
}
988
+ await self . updateIndexStore (
989
+ for: fileAndOutputPaths,
990
+ target: target,
991
+ language: language,
992
+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
993
+ preparationTaskID: preparationTaskID,
994
+ priority: priority
995
+ )
990
996
}
991
997
}
992
998
await taskGroup. waitForAll ( )
0 commit comments