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