@@ -221,12 +221,14 @@ public final actor SemanticIndexManager {
221
221
///
222
222
/// If `files` contains a header file, this will return a `FileToIndex` that re-indexes a main file which includes the
223
223
/// header file to update the header file's index.
224
- private func filesToIndex( toCover files: some Collection < DocumentURI > ) async -> [ FileToIndex ] {
224
+ private func filesToIndex(
225
+ toCover files: some Collection < DocumentURI >
226
+ ) async -> [ FileToIndex ] {
225
227
let sourceFiles = Set ( await buildSystemManager. sourceFiles ( ) . map ( \. uri) )
226
228
let filesToReIndex = await files. asyncCompactMap { ( uri) -> FileToIndex ? in
227
229
if sourceFiles. contains ( uri) {
228
230
// If this is a source file, just index it.
229
- return FileToIndex ( uri: uri , mainFile : nil )
231
+ return . indexableFile ( uri)
230
232
}
231
233
// Otherwise, see if it is a header file. If so, index a main file that that imports it to update header file's
232
234
// index.
@@ -239,7 +241,7 @@ public final actor SemanticIndexManager {
239
241
guard let mainFile else {
240
242
return nil
241
243
}
242
- return FileToIndex ( uri : uri, mainFile: mainFile)
244
+ return . headerFile ( header : uri, mainFile: mainFile)
243
245
}
244
246
return filesToReIndex
245
247
}
@@ -338,10 +340,10 @@ public final actor SemanticIndexManager {
338
340
}
339
341
340
342
/// Update the index store for the given files, assuming that their targets have already been prepared.
341
- private func updateIndexStore( for files: [ FileToIndex ] , taskID: UUID , priority: TaskPriority ? ) async {
343
+ private func updateIndexStore( for files: [ FileAndTarget ] , taskID: UUID , priority: TaskPriority ? ) async {
342
344
let taskDescription = AnyIndexTaskDescription (
343
345
UpdateIndexStoreTaskDescription (
344
- filesToIndex: Set ( files) ,
346
+ filesToIndex: files,
345
347
buildSystemManager: self . buildSystemManager,
346
348
index: index
347
349
)
@@ -350,21 +352,21 @@ public final actor SemanticIndexManager {
350
352
switch newState {
351
353
case . executing:
352
354
for file in files {
353
- if case . scheduled( ( taskID, let task) ) = self . indexStatus [ file. uri ] {
354
- self . indexStatus [ file. uri ] = . executing( ( taskID, task) )
355
+ if case . scheduled( ( taskID, let task) ) = self . indexStatus [ file. file . sourceFile ] {
356
+ self . indexStatus [ file. file . sourceFile ] = . executing( ( taskID, task) )
355
357
}
356
358
}
357
359
case . cancelledToBeRescheduled:
358
360
for file in files {
359
- if case . executing( ( taskID, let task) ) = self . indexStatus [ file. uri ] {
360
- self . indexStatus [ file. uri ] = . scheduled( ( taskID, task) )
361
+ if case . executing( ( taskID, let task) ) = self . indexStatus [ file. file . sourceFile ] {
362
+ self . indexStatus [ file. file . sourceFile ] = . scheduled( ( taskID, task) )
361
363
}
362
364
}
363
365
case . finished:
364
366
for file in files {
365
- switch self . indexStatus [ file. uri ] {
367
+ switch self . indexStatus [ file. file . sourceFile ] {
366
368
case . executing( ( taskID, _) ) :
367
- self . indexStatus [ file. uri ] = . upToDate
369
+ self . indexStatus [ file. file . sourceFile ] = . upToDate
368
370
default :
369
371
break
370
372
}
@@ -383,24 +385,25 @@ public final actor SemanticIndexManager {
383
385
priority: TaskPriority ?
384
386
) async -> Task < Void , Never > {
385
387
let outOfDateFiles = await filesToIndex ( toCover: files) . filter {
386
- if case . upToDate = indexStatus [ $0. uri ] {
388
+ if case . upToDate = indexStatus [ $0. sourceFile ] {
387
389
return false
388
390
}
389
391
return true
390
392
}
391
- . sorted ( by: { $0. uri. stringValue < $1. uri. stringValue } ) // sort files to get deterministic indexing order
393
+ // sort files to get deterministic indexing order
394
+ . sorted ( by: { $0. sourceFile. stringValue < $1. sourceFile. stringValue } )
392
395
393
396
// Sort the targets in topological order so that low-level targets get built before high-level targets, allowing us
394
397
// to index the low-level targets ASAP.
395
398
var filesByTarget : [ ConfiguredTarget : [ FileToIndex ] ] = [ : ]
396
- for file in outOfDateFiles {
397
- guard let target = await buildSystemManager. canonicalConfiguredTarget ( for: file . mainFile ?? file . uri ) else {
399
+ for fileToIndex in outOfDateFiles {
400
+ guard let target = await buildSystemManager. canonicalConfiguredTarget ( for: fileToIndex . mainFile) else {
398
401
logger. error (
399
- " Not indexing \( file . uri . forLogging) because the target could not be determined for main file \( file . mainFile ? . forLogging ) "
402
+ " Not indexing \( fileToIndex . forLogging) because the target could not be determined "
400
403
)
401
404
continue
402
405
}
403
- filesByTarget [ target, default: [ ] ] . append ( file )
406
+ filesByTarget [ target, default: [ ] ] . append ( fileToIndex )
404
407
}
405
408
406
409
var sortedTargets : [ ConfiguredTarget ] =
@@ -440,7 +443,11 @@ public final actor SemanticIndexManager {
440
443
// https://github.com/apple/sourcekit-lsp/issues/1268
441
444
for fileBatch in filesByTarget [ target] !. partition ( intoBatchesOfSize: 1 ) {
442
445
taskGroup. addTask {
443
- await self . updateIndexStore ( for: fileBatch, taskID: taskID, priority: priority)
446
+ await self . updateIndexStore (
447
+ for: fileBatch. map { FileAndTarget ( file: $0, target: target) } ,
448
+ taskID: taskID,
449
+ priority: priority
450
+ )
444
451
}
445
452
}
446
453
}
@@ -455,7 +462,7 @@ public final actor SemanticIndexManager {
455
462
// setting it to `.scheduled` because we don't have an `await` call between the creation of `indexTask` and
456
463
// this loop, so we still have exclusive access to the `SemanticIndexManager` actor and hence `updateIndexStore`
457
464
// can't execute until we have set all index statuses to `.scheduled`.
458
- indexStatus [ file. uri ] = . scheduled( ( taskID, indexTask) )
465
+ indexStatus [ file. sourceFile ] = . scheduled( ( taskID, indexTask) )
459
466
}
460
467
indexTasksWereScheduled ( filesToIndex. count)
461
468
}
0 commit comments