@@ -94,6 +94,7 @@ private struct InProgressIndexStore {
94
94
/// The information that's needed to index a file within a given target.
95
95
package struct FileIndexInfo : Sendable , Hashable {
96
96
package let file : FileToIndex
97
+ package let language : Language
97
98
package let target : BuildTargetIdentifier
98
99
package let outputPath : OutputPath
99
100
}
@@ -507,10 +508,13 @@ package final actor SemanticIndexManager {
507
508
continue
508
509
}
509
510
// If this is a source file, just index it.
511
+ guard let language = await buildServerManager. defaultLanguage ( for: uri, in: target) else {
512
+ continue
513
+ }
510
514
didFindTargetToIndex = true
511
515
filesToReIndex. append (
512
516
(
513
- FileIndexInfo ( file: . indexableFile( uri) , target: target, outputPath: outputPath) ,
517
+ FileIndexInfo ( file: . indexableFile( uri) , language : language , target: target, outputPath: outputPath) ,
514
518
modifiedFilesIndex. modificationDate ( of: uri)
515
519
)
516
520
)
@@ -550,10 +554,14 @@ package final actor SemanticIndexManager {
550
554
{
551
555
continue
552
556
}
557
+ guard let language = await buildServerManager. defaultLanguage ( for: uri, in: targetAndOutputPath. key) else {
558
+ continue
559
+ }
553
560
filesToReIndex. append (
554
561
(
555
562
FileIndexInfo (
556
563
file: . headerFile( header: uri, mainFile: mainFile) ,
564
+ language: language,
557
565
target: targetAndOutputPath. key,
558
566
outputPath: outputPath
559
567
) ,
@@ -733,6 +741,7 @@ package final actor SemanticIndexManager {
733
741
private func updateIndexStore(
734
742
for fileAndOutputPaths: [ FileAndOutputPath ] ,
735
743
target: BuildTargetIdentifier ,
744
+ language: Language ,
736
745
indexFilesWithUpToDateUnit: Bool ,
737
746
preparationTaskID: UUID ,
738
747
priority: TaskPriority ?
@@ -741,6 +750,7 @@ package final actor SemanticIndexManager {
741
750
UpdateIndexStoreTaskDescription (
742
751
filesToIndex: fileAndOutputPaths,
743
752
target: target,
753
+ language: language,
744
754
buildServerManager: self . buildServerManager,
745
755
index: index,
746
756
indexStoreUpToDateTracker: indexStoreUpToDateTracker,
@@ -759,6 +769,7 @@ package final actor SemanticIndexManager {
759
769
for fileAndOutputPath in fileAndOutputPaths {
760
770
let fileAndTarget = FileIndexInfo (
761
771
file: fileAndOutputPath. file,
772
+ language: language,
762
773
target: target,
763
774
outputPath: fileAndOutputPath. outputPath
764
775
)
@@ -780,6 +791,7 @@ package final actor SemanticIndexManager {
780
791
for fileAndOutputPath in fileAndOutputPaths {
781
792
let fileAndTarget = FileIndexInfo (
782
793
file: fileAndOutputPath. file,
794
+ language: language,
783
795
target: target,
784
796
outputPath: fileAndOutputPath. outputPath
785
797
)
@@ -873,13 +885,7 @@ package final actor SemanticIndexManager {
873
885
var newIndexTasks = 0
874
886
875
887
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 {
883
889
continue
884
890
}
885
891
@@ -952,27 +958,34 @@ package final actor SemanticIndexManager {
952
958
// And after preparation is done, index the files in the targets.
953
959
await withTaskGroup ( of: Void . self) { taskGroup in
954
960
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)
966
979
}
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
+ )
968
988
}
969
- await self . updateIndexStore (
970
- for: fileAndOutputPaths,
971
- target: target,
972
- indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
973
- preparationTaskID: preparationTaskID,
974
- priority: priority
975
- )
976
989
}
977
990
}
978
991
}
0 commit comments