Skip to content

Commit fb0801a

Browse files
authored
Merge pull request #1311 from ahoppen/review-comments-1307
Don't re-prepare a target if there is already a smaller preparation task for it scheduled
2 parents c2af2f5 + c1073a4 commit fb0801a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,19 @@ public final actor SemanticIndexManager {
268268
switch preparationStatus[target] {
269269
case .upToDate:
270270
break
271-
case .scheduled((_, let configuredTargets, let task)), .executing((_, let configuredTargets, let task)):
271+
case .scheduled((_, let existingTaskTargets, let task)), .executing((_, let existingTaskTargets, let task)):
272272
// If we already have a task scheduled that prepares fewer targets, await that instead of overriding the
273273
// target's preparation status with a longer-running task. The key benefit here is that when we get many
274274
// preparation requests for the same target (eg. one for every text document request sent to a file), we don't
275275
// re-create new `PreparationTaskDescription`s for every preparation request. Instead, all the preparation
276276
// requests await the same task. At the same time, if we have a multi-file preparation request and then get a
277277
// single-file preparation request, we will override the preparation of that target with the single-file
278278
// preparation task, ensuring that the task gets prepared as quickly as possible.
279-
if configuredTargets.count <= targets.count {
279+
if existingTaskTargets.count <= targets.count {
280280
preparationTasksToAwait.append(task)
281+
} else {
282+
targetsToPrepare.append(target)
281283
}
282-
fallthrough
283284
case nil:
284285
targetsToPrepare.append(target)
285286
}

0 commit comments

Comments
 (0)