Always let two completions race with each other (#21919)

When a user types, chances are the model will anticipate what they are
about to do. Previously, we would continuously cancel the pending
completion until the user stopped typing. With this commit, we allow at
most two completions to race with each other (the first and the last
one):

- If the completion that was requested first completes first, we will
show it (assuming we can interpolate it) but avoid canceling the last
one.
- When the completion that was requested last completes, we will cancel
the first one if it's pending.

In both cases, if a completion is already on-screen we have a special
case for when the completions are just insertions and the new completion
is a superset of the existing one. In this case, we will replace the
existing completion with the new one. Otherwise we will keep showing the
old one to avoid thrashing the UI.

This should make latency a lot better. Note that I also reduced the
debounce timeout to 8ms.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-12-12 16:01:05 +01:00 committed by GitHub
parent 91b02a6259
commit ad4c4aff13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 124 additions and 46 deletions

View file

@ -344,6 +344,7 @@ impl RateCompletionModal {
};
let rated = self.zeta.read(cx).is_completion_rated(completion_id);
let was_shown = self.zeta.read(cx).was_completion_shown(completion_id);
let feedback_empty = active_completion
.feedback_editor
.read(cx)
@ -426,6 +427,16 @@ impl RateCompletionModal {
)
.child(Label::new("No edits produced.").color(Color::Muted)),
)
} else if !was_shown {
Some(
label_container()
.child(
Icon::new(IconName::Warning)
.size(IconSize::Small)
.color(Color::Warning),
)
.child(Label::new("Completion wasn't shown because another valid completion was already on screen").color(Color::Warning)),
)
} else {
Some(label_container())
})