@@ -238,15 +238,15 @@ public final actor SemanticIndexManager {
238238 /// Returns immediately after scheduling that task.
239239 ///
240240 /// 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)
243243 }
244244
245245 /// Regenerate the build graph (also resolving package dependencies) and then index all the source files known to the
246246 /// build system that don't currently have a unit with a timestamp that matches the mtime of the file.
247247 ///
248248 /// 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 {
250250 generateBuildGraphTask = Task ( priority: . low) {
251251 await withLoggingSubsystemAndScope ( subsystem: indexLoggingSubsystem, scope: " build-graph-generation " ) {
252252 logger. log (
@@ -270,16 +270,26 @@ public final actor SemanticIndexManager {
270270 // potentially not knowing about unit files, which causes the corresponding source files to be re-indexed.
271271 index. pollForUnitChangesAndWait ( )
272272 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)
277279 generateBuildGraphTask = nil
278280 }
279281 }
280282 indexProgressStatusDidChange ( )
281283 }
282284
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+
283293 /// Wait for all in-progress index tasks to finish.
284294 public func waitForUpToDateIndex( ) async {
285295 logger. info ( " Waiting for up-to-date index " )
@@ -319,7 +329,7 @@ public final actor SemanticIndexManager {
319329 // Create a new index task for the files that aren't up-to-date. The newly scheduled index tasks will
320330 // - Wait for the existing index operations to finish if they have the same number of files.
321331 // - 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
323333 index. pollForUnitChangesAndWait ( )
324334 logger. debug ( " Done waiting for up-to-date index " )
325335 }
@@ -354,7 +364,7 @@ public final actor SemanticIndexManager {
354364 await preparationUpToDateTracker. markOutOfDate ( inProgressPreparationTasks. keys)
355365 }
356366
357- await scheduleBackgroundIndex ( files: changedFiles)
367+ await scheduleBackgroundIndex ( files: changedFiles, indexFilesWithUpToDateUnit : false )
358368 }
359369
360370 /// 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 {
507517 /// Update the index store for the given files, assuming that their targets have already been prepared.
508518 private func updateIndexStore(
509519 for filesAndTargets: [ FileAndTarget ] ,
520+ indexFilesWithUpToDateUnit: Bool ,
510521 preparationTaskID: UUID ,
511522 priority: TaskPriority ?
512523 ) async {
@@ -516,6 +527,7 @@ public final actor SemanticIndexManager {
516527 buildSystemManager: self . buildSystemManager,
517528 index: index,
518529 indexStoreUpToDateTracker: indexStoreUpToDateTracker,
530+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
519531 logMessageToIndexLog: logMessageToIndexLog,
520532 timeout: updateIndexStoreTimeout,
521533 testHooks: testHooks
@@ -553,6 +565,7 @@ public final actor SemanticIndexManager {
553565 /// The returned task finishes when all files are indexed.
554566 private func scheduleIndexing(
555567 of files: some Collection < DocumentURI > ,
568+ indexFilesWithUpToDateUnit: Bool ,
556569 priority: TaskPriority ?
557570 ) async -> Task < Void , Never > {
558571 // 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 {
627640 taskGroup. addTask {
628641 await self . updateIndexStore (
629642 for: fileBatch. map { FileAndTarget ( file: $0, target: target) } ,
643+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
630644 preparationTaskID: preparationTaskID,
631645 priority: priority
632646 )
0 commit comments