@@ -238,15 +238,15 @@ public final actor SemanticIndexManager {
238
238
/// Returns immediately after scheduling that task.
239
239
///
240
240
/// Indexing is being performed with a low priority.
241
- private func scheduleBackgroundIndex( files: some Collection < DocumentURI > ) async {
242
- _ = await self . scheduleIndexing ( of: files, priority: . low)
241
+ private func scheduleBackgroundIndex( files: some Collection < DocumentURI > , indexFilesWithUpToDateUnit : Bool ) async {
242
+ _ = await self . scheduleIndexing ( of: files, indexFilesWithUpToDateUnit : indexFilesWithUpToDateUnit , priority: . low)
243
243
}
244
244
245
245
/// Regenerate the build graph (also resolving package dependencies) and then index all the source files known to the
246
246
/// build system that don't currently have a unit with a timestamp that matches the mtime of the file.
247
247
///
248
248
/// This method is intended to initially update the index of a project after it is opened.
249
- public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles( ) async {
249
+ public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles( indexFilesWithUpToDateUnit : Bool = false ) async {
250
250
generateBuildGraphTask = Task ( priority: . low) {
251
251
await withLoggingSubsystemAndScope ( subsystem: indexLoggingSubsystem, scope: " build-graph-generation " ) {
252
252
logger. log (
@@ -270,16 +270,26 @@ public final actor SemanticIndexManager {
270
270
// potentially not knowing about unit files, which causes the corresponding source files to be re-indexed.
271
271
index. pollForUnitChangesAndWait ( )
272
272
await testHooks. buildGraphGenerationDidFinish ? ( )
273
- let index = index. checked ( for: . modifiedFiles)
274
- let filesToIndex = await self . buildSystemManager. sourceFiles ( ) . lazy. map ( \. uri)
275
- . filter { !index. hasUpToDateUnit ( for: $0) }
276
- await scheduleBackgroundIndex ( files: filesToIndex)
273
+ var filesToIndex : any Collection < DocumentURI > = await self . buildSystemManager. sourceFiles ( ) . lazy. map ( \. uri)
274
+ if !indexFilesWithUpToDateUnit {
275
+ let index = index. checked ( for: . modifiedFiles)
276
+ filesToIndex = filesToIndex. filter { !index. hasUpToDateUnit ( for: $0) }
277
+ }
278
+ await scheduleBackgroundIndex ( files: filesToIndex, indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit)
277
279
generateBuildGraphTask = nil
278
280
}
279
281
}
280
282
indexProgressStatusDidChange ( )
281
283
}
282
284
285
+ /// Causes all files to be re-indexed even if the unit file for the source file is up to date.
286
+ /// See `TriggerReindexRequest`.
287
+ public func scheduleReindex( ) async {
288
+ await indexStoreUpToDateTracker. markAllKnownOutOfDate ( )
289
+ await preparationUpToDateTracker. markAllKnownOutOfDate ( )
290
+ await scheduleBuildGraphGenerationAndBackgroundIndexAllFiles ( indexFilesWithUpToDateUnit: true )
291
+ }
292
+
283
293
/// Wait for all in-progress index tasks to finish.
284
294
public func waitForUpToDateIndex( ) async {
285
295
logger. info ( " Waiting for up-to-date index " )
@@ -319,7 +329,7 @@ public final actor SemanticIndexManager {
319
329
// Create a new index task for the files that aren't up-to-date. The newly scheduled index tasks will
320
330
// - Wait for the existing index operations to finish if they have the same number of files.
321
331
// - Reschedule the background index task in favor of an index task with fewer source files.
322
- await self . scheduleIndexing ( of: uris, priority: nil ) . value
332
+ await self . scheduleIndexing ( of: uris, indexFilesWithUpToDateUnit : false , priority: nil ) . value
323
333
index. pollForUnitChangesAndWait ( )
324
334
logger. debug ( " Done waiting for up-to-date index " )
325
335
}
@@ -354,7 +364,7 @@ public final actor SemanticIndexManager {
354
364
await preparationUpToDateTracker. markOutOfDate ( inProgressPreparationTasks. keys)
355
365
}
356
366
357
- await scheduleBackgroundIndex ( files: changedFiles)
367
+ await scheduleBackgroundIndex ( files: changedFiles, indexFilesWithUpToDateUnit : false )
358
368
}
359
369
360
370
/// Returns the files that should be indexed to get up-to-date index information for the given files.
@@ -507,6 +517,7 @@ public final actor SemanticIndexManager {
507
517
/// Update the index store for the given files, assuming that their targets have already been prepared.
508
518
private func updateIndexStore(
509
519
for filesAndTargets: [ FileAndTarget ] ,
520
+ indexFilesWithUpToDateUnit: Bool ,
510
521
preparationTaskID: UUID ,
511
522
priority: TaskPriority ?
512
523
) async {
@@ -516,6 +527,7 @@ public final actor SemanticIndexManager {
516
527
buildSystemManager: self . buildSystemManager,
517
528
index: index,
518
529
indexStoreUpToDateTracker: indexStoreUpToDateTracker,
530
+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
519
531
logMessageToIndexLog: logMessageToIndexLog,
520
532
timeout: updateIndexStoreTimeout,
521
533
testHooks: testHooks
@@ -553,6 +565,7 @@ public final actor SemanticIndexManager {
553
565
/// The returned task finishes when all files are indexed.
554
566
private func scheduleIndexing(
555
567
of files: some Collection < DocumentURI > ,
568
+ indexFilesWithUpToDateUnit: Bool ,
556
569
priority: TaskPriority ?
557
570
) async -> Task < Void , Never > {
558
571
// Perform a quick initial check to whether the files is up-to-date, in which case we don't need to schedule a
@@ -627,6 +640,7 @@ public final actor SemanticIndexManager {
627
640
taskGroup. addTask {
628
641
await self . updateIndexStore (
629
642
for: fileBatch. map { FileAndTarget ( file: $0, target: target) } ,
643
+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
630
644
preparationTaskID: preparationTaskID,
631
645
priority: priority
632
646
)
0 commit comments