@@ -231,15 +231,15 @@ public final actor SemanticIndexManager {
231
231
/// Returns immediately after scheduling that task.
232
232
///
233
233
/// Indexing is being performed with a low priority.
234
- private func scheduleBackgroundIndex( files: some Collection < DocumentURI > ) async {
235
- _ = await self . scheduleIndexing ( of: files, priority: . low)
234
+ private func scheduleBackgroundIndex( files: some Collection < DocumentURI > , indexFilesWithUpToDateUnit : Bool ) async {
235
+ _ = await self . scheduleIndexing ( of: files, indexFilesWithUpToDateUnit : indexFilesWithUpToDateUnit , priority: . low)
236
236
}
237
237
238
238
/// Regenerate the build graph (also resolving package dependencies) and then index all the source files known to the
239
239
/// build system that don't currently have a unit with a timestamp that matches the mtime of the file.
240
240
///
241
241
/// This method is intended to initially update the index of a project after it is opened.
242
- public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles( ) async {
242
+ public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles( indexFilesWithUpToDateUnit : Bool = false ) async {
243
243
generateBuildGraphTask = Task ( priority: . low) {
244
244
await withLoggingSubsystemAndScope ( subsystem: indexLoggingSubsystem, scope: " build-graph-generation " ) {
245
245
logger. log (
@@ -263,16 +263,26 @@ public final actor SemanticIndexManager {
263
263
// potentially not knowing about unit files, which causes the corresponding source files to be re-indexed.
264
264
index. pollForUnitChangesAndWait ( )
265
265
await testHooks. buildGraphGenerationDidFinish ? ( )
266
- let index = index. checked ( for: . modifiedFiles)
267
- let filesToIndex = await self . buildSystemManager. sourceFiles ( ) . lazy. map ( \. uri)
268
- . filter { !index. hasUpToDateUnit ( for: $0) }
269
- await scheduleBackgroundIndex ( files: filesToIndex)
266
+ var filesToIndex : any Collection < DocumentURI > = await self . buildSystemManager. sourceFiles ( ) . lazy. map ( \. uri)
267
+ if !indexFilesWithUpToDateUnit {
268
+ let index = index. checked ( for: . modifiedFiles)
269
+ filesToIndex = filesToIndex. filter { !index. hasUpToDateUnit ( for: $0) }
270
+ }
271
+ await scheduleBackgroundIndex ( files: filesToIndex, indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit)
270
272
generateBuildGraphTask = nil
271
273
}
272
274
}
273
275
indexProgressStatusDidChange ( )
274
276
}
275
277
278
+ /// Causes all files to be re-indexed even if the unit file for the source file is up to date.
279
+ /// See `TriggerReindexRequest`.
280
+ public func scheduleReindex( ) async {
281
+ await indexStoreUpToDateTracker. markAllKnownOutOfDate ( )
282
+ await preparationUpToDateTracker. markAllKnownOutOfDate ( )
283
+ await scheduleBuildGraphGenerationAndBackgroundIndexAllFiles ( indexFilesWithUpToDateUnit: true )
284
+ }
285
+
276
286
/// Wait for all in-progress index tasks to finish.
277
287
public func waitForUpToDateIndex( ) async {
278
288
logger. info ( " Waiting for up-to-date index " )
@@ -312,7 +322,7 @@ public final actor SemanticIndexManager {
312
322
// Create a new index task for the files that aren't up-to-date. The newly scheduled index tasks will
313
323
// - Wait for the existing index operations to finish if they have the same number of files.
314
324
// - Reschedule the background index task in favor of an index task with fewer source files.
315
- await self . scheduleIndexing ( of: uris, priority: nil ) . value
325
+ await self . scheduleIndexing ( of: uris, indexFilesWithUpToDateUnit : false , priority: nil ) . value
316
326
index. pollForUnitChangesAndWait ( )
317
327
logger. debug ( " Done waiting for up-to-date index " )
318
328
}
@@ -347,7 +357,7 @@ public final actor SemanticIndexManager {
347
357
await preparationUpToDateTracker. markOutOfDate ( inProgressPreparationTasks. keys)
348
358
}
349
359
350
- await scheduleBackgroundIndex ( files: changedFiles)
360
+ await scheduleBackgroundIndex ( files: changedFiles, indexFilesWithUpToDateUnit : false )
351
361
}
352
362
353
363
/// Returns the files that should be indexed to get up-to-date index information for the given files.
@@ -500,6 +510,7 @@ public final actor SemanticIndexManager {
500
510
/// Update the index store for the given files, assuming that their targets have already been prepared.
501
511
private func updateIndexStore(
502
512
for filesAndTargets: [ FileAndTarget ] ,
513
+ indexFilesWithUpToDateUnit: Bool ,
503
514
preparationTaskID: UUID ,
504
515
priority: TaskPriority ?
505
516
) async {
@@ -509,6 +520,7 @@ public final actor SemanticIndexManager {
509
520
buildSystemManager: self . buildSystemManager,
510
521
index: index,
511
522
indexStoreUpToDateTracker: indexStoreUpToDateTracker,
523
+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
512
524
logMessageToIndexLog: logMessageToIndexLog,
513
525
testHooks: testHooks
514
526
)
@@ -545,6 +557,7 @@ public final actor SemanticIndexManager {
545
557
/// The returned task finishes when all files are indexed.
546
558
private func scheduleIndexing(
547
559
of files: some Collection < DocumentURI > ,
560
+ indexFilesWithUpToDateUnit: Bool ,
548
561
priority: TaskPriority ?
549
562
) async -> Task < Void , Never > {
550
563
// Perform a quick initial check to whether the files is up-to-date, in which case we don't need to schedule a
@@ -619,6 +632,7 @@ public final actor SemanticIndexManager {
619
632
taskGroup. addTask {
620
633
await self . updateIndexStore (
621
634
for: fileBatch. map { FileAndTarget ( file: $0, target: target) } ,
635
+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
622
636
preparationTaskID: preparationTaskID,
623
637
priority: priority
624
638
)
0 commit comments