Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Cancel ongoing completion requests more eagerly (#12630)
Piotr Osiewicz8e7960928809
diff --git a/crates/editor/src/debounced_delay.rs b/crates/editor/src/debounced_delay.rsindex b9d8ebf1037..0dbf36d49e3 100644--- a/crates/editor/src/debounced_delay.rs+++ b/crates/editor/src/debounced_delay.rs@@ -29,13 +29,9 @@ impl DebouncedDelay {let (sender, mut receiver) = oneshot::channel::<()>();self.cancel_channel = Some(sender);- let previous_task = self.task.take();+ drop(self.task.take());self.task = Some(cx.spawn(move |model, mut cx| async move {let mut timer = cx.background_executor().timer(delay).fuse();- if let Some(previous_task) = previous_task {- previous_task.await;- }-futures::select_biased! {_ = receiver => return,_ = timer => {}diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 3c472540c02..3b75fdab8f0 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -15,18 +15,17 @@pub mod actions;mod blame_entry_tooltip;mod blink_manager;+mod debounced_delay;pub mod display_map;mod editor_settings;mod element;-mod hunk_diff;-mod inlay_hint_cache;--mod debounced_delay;mod git;mod highlight_matching_bracket;mod hover_links;mod hover_popover;+mod hunk_diff;mod indent_guides;+mod inlay_hint_cache;mod inline_completion_provider;pub mod items;mod mouse_context_menu;@@ -3806,6 +3805,9 @@ impl Editor {let id = post_inc(&mut self.next_completion_id);let task = cx.spawn(|this, mut cx| {async move {+ this.update(&mut cx, |this, _| {+ this.completion_tasks.retain(|(task_id, _)| *task_id >= id);+ })?;let completions = completions.await.log_err();let menu = if let Some(completions) = completions {let mut menu = CompletionsMenu {@@ -3844,7 +3846,6 @@ impl Editor {let delay_ms = EditorSettings::get_global(cx).completion_documentation_secondary_query_debounce;let delay = Duration::from_millis(delay_ms);-editor.completion_documentation_pre_resolve_debounce.fire_new(delay, cx, |editor, cx| {@@ -3865,8 +3866,6 @@ impl Editor {};this.update(&mut cx, |this, cx| {- this.completion_tasks.retain(|(task_id, _)| *task_id >= id);-let mut context_menu = this.context_menu.write();match context_menu.as_ref() {None => {}