@@ -151,12 +151,36 @@ actor SyntacticTestIndex {
151
151
152
152
/// Called when a list of files was updated. Re-scans those files
153
153
private func rescanFiles( _ uris: [ DocumentURI ] ) {
154
- logger. info ( " Syntactically scanning files for tests: \( uris) " )
155
-
156
154
// If we scan a file again, it might have been added after being removed before. Remove it from the list of removed
157
155
// files.
158
156
removedFiles. subtract ( uris)
159
157
158
+ // If we already know that the file has an up-to-date index, avoid re-scheduling it to be indexed. This ensures
159
+ // that we don't bloat `indexingQueue` if the build system is sending us repeated `buildTarget/didChange`
160
+ // notifications.
161
+ // This check does not need to be perfect and there might be an in-progress index operation that is about to index
162
+ // the file. In that case we still schedule anothe rescan of that file and notice in `rescanFilesAssumingOnQueue`
163
+ // that the index is already up-to-date, which makes the rescan a no-op.
164
+ let uris = uris. filter { uri in
165
+ if let url = uri. fileURL,
166
+ let indexModificationDate = self . indexedTests [ uri] ? . sourceFileModificationDate,
167
+ let fileModificationDate = try ? FileManager . default. attributesOfItem ( atPath: url. filePath) [ . modificationDate]
168
+ as? Date ,
169
+ indexModificationDate >= fileModificationDate
170
+ {
171
+ return false
172
+ }
173
+ return true
174
+ }
175
+
176
+ guard !uris. isEmpty else {
177
+ return
178
+ }
179
+
180
+ logger. info (
181
+ " Syntactically scanning \( uris. count) files for tests: \( uris. map ( \. arbitrarySchemeURL. lastPathComponent) . joined ( separator: " , " ) ) "
182
+ )
183
+
160
184
// Divide the files into multiple batches. This is more efficient than spawning a new task for every file, mostly
161
185
// because it keeps the number of pending items in `indexingQueue` low and adding a new task to `indexingQueue` is
162
186
// in O(number of pending tasks), since we need to scan for dependency edges to add, which would make scanning files
0 commit comments