@@ -231,15 +231,15 @@ public final actor SemanticIndexManager {
231231 /// Returns immediately after scheduling that task.
232232 ///
233233 /// 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)
236236 }
237237
238238 /// Regenerate the build graph (also resolving package dependencies) and then index all the source files known to the
239239 /// build system that don't currently have a unit with a timestamp that matches the mtime of the file.
240240 ///
241241 /// 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 {
243243 generateBuildGraphTask = Task ( priority: . low) {
244244 await withLoggingSubsystemAndScope ( subsystem: indexLoggingSubsystem, scope: " build-graph-generation " ) {
245245 logger. log (
@@ -263,16 +263,26 @@ public final actor SemanticIndexManager {
263263 // potentially not knowing about unit files, which causes the corresponding source files to be re-indexed.
264264 index. pollForUnitChangesAndWait ( )
265265 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)
270272 generateBuildGraphTask = nil
271273 }
272274 }
273275 indexProgressStatusDidChange ( )
274276 }
275277
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+
276286 /// Wait for all in-progress index tasks to finish.
277287 public func waitForUpToDateIndex( ) async {
278288 logger. info ( " Waiting for up-to-date index " )
@@ -312,7 +322,7 @@ public final actor SemanticIndexManager {
312322 // Create a new index task for the files that aren't up-to-date. The newly scheduled index tasks will
313323 // - Wait for the existing index operations to finish if they have the same number of files.
314324 // - 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
316326 index. pollForUnitChangesAndWait ( )
317327 logger. debug ( " Done waiting for up-to-date index " )
318328 }
@@ -347,7 +357,7 @@ public final actor SemanticIndexManager {
347357 await preparationUpToDateTracker. markOutOfDate ( inProgressPreparationTasks. keys)
348358 }
349359
350- await scheduleBackgroundIndex ( files: changedFiles)
360+ await scheduleBackgroundIndex ( files: changedFiles, indexFilesWithUpToDateUnit : false )
351361 }
352362
353363 /// 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 {
500510 /// Update the index store for the given files, assuming that their targets have already been prepared.
501511 private func updateIndexStore(
502512 for filesAndTargets: [ FileAndTarget ] ,
513+ indexFilesWithUpToDateUnit: Bool ,
503514 preparationTaskID: UUID ,
504515 priority: TaskPriority ?
505516 ) async {
@@ -509,6 +520,7 @@ public final actor SemanticIndexManager {
509520 buildSystemManager: self . buildSystemManager,
510521 index: index,
511522 indexStoreUpToDateTracker: indexStoreUpToDateTracker,
523+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
512524 logMessageToIndexLog: logMessageToIndexLog,
513525 testHooks: testHooks
514526 )
@@ -545,6 +557,7 @@ public final actor SemanticIndexManager {
545557 /// The returned task finishes when all files are indexed.
546558 private func scheduleIndexing(
547559 of files: some Collection < DocumentURI > ,
560+ indexFilesWithUpToDateUnit: Bool ,
548561 priority: TaskPriority ?
549562 ) async -> Task < Void , Never > {
550563 // 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 {
619632 taskGroup. addTask {
620633 await self . updateIndexStore (
621634 for: fileBatch. map { FileAndTarget ( file: $0, target: target) } ,
635+ indexFilesWithUpToDateUnit: indexFilesWithUpToDateUnit,
622636 preparationTaskID: preparationTaskID,
623637 priority: priority
624638 )
0 commit comments