@@ -94,6 +94,7 @@ private struct InProgressIndexStore {
9494/// The information that's needed to index a file within a given target.
9595package struct FileIndexInfo : Sendable , Hashable {
9696 package let file : FileToIndex
97+ package let language : Language
9798 package let target : BuildTargetIdentifier
9899 package let outputPath : OutputPath
99100}
@@ -507,10 +508,13 @@ package final actor SemanticIndexManager {
507508 continue
508509 }
509510 // If this is a source file, just index it.
511+ guard let language = await buildServerManager. defaultLanguage ( for: uri, in: target) else {
512+ continue
513+ }
510514 didFindTargetToIndex = true
511515 filesToReIndex. append (
512516 (
513- FileIndexInfo ( file: . indexableFile( uri) , target: target, outputPath: outputPath) ,
517+ FileIndexInfo ( file: . indexableFile( uri) , language : language , target: target, outputPath: outputPath) ,
514518 modifiedFilesIndex. modificationDate ( of: uri)
515519 )
516520 )
@@ -550,10 +554,14 @@ package final actor SemanticIndexManager {
550554 {
551555 continue
552556 }
557+ guard let language = await buildServerManager. defaultLanguage ( for: uri, in: targetAndOutputPath. key) else {
558+ continue
559+ }
553560 filesToReIndex. append (
554561 (
555562 FileIndexInfo (
556563 file: . headerFile( header: uri, mainFile: mainFile) ,
564+ language: language,
557565 target: targetAndOutputPath. key,
558566 outputPath: outputPath
559567 ) ,
@@ -733,6 +741,7 @@ package final actor SemanticIndexManager {
733741 private func updateIndexStore(
734742 for fileAndOutputPaths: [ FileAndOutputPath ] ,
735743 target: BuildTargetIdentifier ,
744+ language: Language ,
736745 indexFilesWithUpToDateUnit: Bool ,
737746 preparationTaskID: UUID ,
738747 priority: TaskPriority ?
@@ -741,6 +750,7 @@ package final actor SemanticIndexManager {
741750 UpdateIndexStoreTaskDescription (
742751 filesToIndex: fileAndOutputPaths,
743752 target: target,
753+ language: language,
744754 buildServerManager: self . buildServerManager,
745755 index: index,
746756 indexStoreUpToDateTracker: indexStoreUpToDateTracker,
@@ -759,6 +769,7 @@ package final actor SemanticIndexManager {
759769 for fileAndOutputPath in fileAndOutputPaths {
760770 let fileAndTarget = FileIndexInfo (
761771 file: fileAndOutputPath. file,
772+ language: language,
762773 target: target,
763774 outputPath: fileAndOutputPath. outputPath
764775 )
@@ -780,6 +791,7 @@ package final actor SemanticIndexManager {
780791 for fileAndOutputPath in fileAndOutputPaths {
781792 let fileAndTarget = FileIndexInfo (
782793 file: fileAndOutputPath. file,
794+ language: language,
783795 target: target,
784796 outputPath: fileAndOutputPath. outputPath
785797 )
@@ -873,13 +885,7 @@ package final actor SemanticIndexManager {
873885 var newIndexTasks = 0
874886
875887 for (fileIndexInfo, fileModificationDate) in filesToIndex {
876- guard
877- let language = await buildServerManager. defaultLanguage (
878- for: fileIndexInfo. file. mainFile,
879- in: fileIndexInfo. target
880- ) ,
881- UpdateIndexStoreTaskDescription . canIndex ( language: language)
882- else {
888+ guard UpdateIndexStoreTaskDescription . canIndex ( language: fileIndexInfo. language) else {
883889 continue
884890 }
885891
@@ -952,27 +958,34 @@ package final actor SemanticIndexManager {
952958 // And after preparation is done, index the files in the targets.
953959 await withTaskGroup ( of: Void . self) { taskGroup in
954960 for target in targetsBatch {
955- // TODO: Once swiftc supports indexing of multiple files in a single invocation, increase the batch size to
956- // allow it to share AST builds between multiple files within a target.
957- // (https://github.com/swiftlang/sourcekit-lsp/issues/1268)
958- for fileBatch in filesByTarget [ target] !. partition ( intoBatchesOfSize: 1 ) {
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
961+ var filesByLanguage : [ Language : [ FileIndexInfo ] ] = [ : ]
962+ for fileInfo in filesByTarget [ target] ! {
963+ filesByLanguage [ fileInfo. language, default: [ ] ] . append ( fileInfo)
964+ }
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)
966979 }
967- return FileAndOutputPath ( file: $0. file, outputPath: $0. outputPath)
980+ await self . updateIndexStore (
981+ for: fileAndOutputPaths,
982+ target: target,
983+ language: language,
984+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
985+ preparationTaskID: preparationTaskID,
986+ priority: priority
987+ )
968988 }
969- await self . updateIndexStore (
970- for: fileAndOutputPaths,
971- target: target,
972- indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
973- preparationTaskID: preparationTaskID,
974- priority: priority
975- )
976989 }
977990 }
978991 }
0 commit comments