Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Sources/SemanticIndex/SemanticIndexManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,19 @@ public final actor SemanticIndexManager {
switch preparationStatus[target] {
case .upToDate:
break
case .scheduled((_, let configuredTargets, let task)), .executing((_, let configuredTargets, let task)):
case .scheduled((_, let existingTaskTargets, let task)), .executing((_, let existingTaskTargets, let task)):
// If we already have a task scheduled that prepares fewer targets, await that instead of overriding the
// target's preparation status with a longer-running task. The key benefit here is that when we get many
// preparation requests for the same target (eg. one for every text document request sent to a file), we don't
// re-create new `PreparationTaskDescription`s for every preparation request. Instead, all the preparation
// requests await the same task. At the same time, if we have a multi-file preparation request and then get a
// single-file preparation request, we will override the preparation of that target with the single-file
// preparation task, ensuring that the task gets prepared as quickly as possible.
if configuredTargets.count <= targets.count {
if existingTaskTargets.count <= targets.count {
preparationTasksToAwait.append(task)
} else {
targetsToPrepare.append(target)
}
fallthrough
case nil:
targetsToPrepare.append(target)
}
Expand Down