@@ -15,6 +15,9 @@ import LSPLogging
15
15
import LanguageServerProtocol
16
16
import SKCore
17
17
18
+ /// The logging subsystem that should be used for all index-related logging.
19
+ let indexLoggingSubsystem = " org.swift.sourcekit-lsp.indexing "
20
+
18
21
/// A wrapper around `QueuedTask` that only allows equality comparison and inspection whether the `QueuedTask` is
19
22
/// currently executing.
20
23
///
@@ -186,29 +189,38 @@ public final actor SemanticIndexManager {
186
189
/// This method is intended to initially update the index of a project after it is opened.
187
190
public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles( ) async {
188
191
generateBuildGraphTask = Task ( priority: . low) {
189
- let signposter = Logger ( subsystem: LoggingScope . subsystem, category: " preparation " ) . makeSignposter ( )
190
- let signpostID = signposter. makeSignpostID ( )
191
- let state = signposter. beginInterval ( " Preparing " , id: signpostID, " Generating build graph " )
192
- defer {
193
- signposter. endInterval ( " Preparing " , state)
194
- }
195
- await testHooks. buildGraphGenerationDidStart ? ( )
196
- await orLog ( " Generating build graph " ) { try await self . buildSystemManager. generateBuildGraph ( ) }
197
- // Ensure that we have an up-to-date indexstore-db. Waiting for the indexstore-db to be updated is cheaper than
198
- // potentially not knowing about unit files, which causes the corresponding source files to be re-indexed.
199
- index. pollForUnitChangesAndWait ( )
200
- await testHooks. buildGraphGenerationDidFinish ? ( )
201
- let index = index. checked ( for: . modifiedFiles)
202
- let filesToIndex = await self . buildSystemManager. sourceFiles ( ) . lazy. map ( \. uri)
203
- . filter { uri in
204
- guard let url = uri. fileURL else {
205
- // The URI is not a file, so there's nothing we can index.
206
- return false
207
- }
208
- return !index. hasUpToDateUnit ( for: url)
192
+ await withLoggingSubsystemAndScope ( subsystem: indexLoggingSubsystem, scope: " build-graph-generation " ) {
193
+ logger. log (
194
+ " Starting build graph generation with priority \( Task . currentPriority. rawValue, privacy: . public) "
195
+ )
196
+ let signposter = logger. makeSignposter ( )
197
+ let signpostID = signposter. makeSignpostID ( )
198
+ let state = signposter. beginInterval ( " Preparing " , id: signpostID, " Generating build graph " )
199
+ let startDate = Date ( )
200
+ defer {
201
+ logger. log (
202
+ " Finished build graph generation in \( Date ( ) . timeIntervalSince ( startDate) * 1000 , privacy: . public) ms "
203
+ )
204
+ signposter. endInterval ( " Preparing " , state)
209
205
}
210
- await scheduleBackgroundIndex ( files: filesToIndex)
211
- generateBuildGraphTask = nil
206
+ await testHooks. buildGraphGenerationDidStart ? ( )
207
+ await orLog ( " Generating build graph " ) { try await self . buildSystemManager. generateBuildGraph ( ) }
208
+ // Ensure that we have an up-to-date indexstore-db. Waiting for the indexstore-db to be updated is cheaper than
209
+ // potentially not knowing about unit files, which causes the corresponding source files to be re-indexed.
210
+ index. pollForUnitChangesAndWait ( )
211
+ await testHooks. buildGraphGenerationDidFinish ? ( )
212
+ let index = index. checked ( for: . modifiedFiles)
213
+ let filesToIndex = await self . buildSystemManager. sourceFiles ( ) . lazy. map ( \. uri)
214
+ . filter { uri in
215
+ guard let url = uri. fileURL else {
216
+ // The URI is not a file, so there's nothing we can index.
217
+ return false
218
+ }
219
+ return !index. hasUpToDateUnit ( for: url)
220
+ }
221
+ await scheduleBackgroundIndex ( files: filesToIndex)
222
+ generateBuildGraphTask = nil
223
+ }
212
224
}
213
225
indexStatusDidChange ( )
214
226
}
0 commit comments