diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 337520c7e9b14e36fa5725eda6198c4cd0a53832..5c4157d4c44d16ff34fab3984a84ef5a3c2493dd 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -48,7 +48,7 @@ use project::{ }; use serde_json::{self, json}; use settings::{ - AllLanguageSettingsContent, EditorSettingsContent, IndentGuideBackgroundColoring, + AllLanguageSettingsContent, DelayMs, EditorSettingsContent, IndentGuideBackgroundColoring, IndentGuideColoring, InlayHintSettingsContent, ProjectSettingsContent, SearchSettingsContent, SettingsStore, }; @@ -13544,6 +13544,7 @@ async fn test_handle_input_for_show_signature_help_auto_signature_help_true( cx.update_global::(|settings, cx| { settings.update_user_settings(cx, |settings| { settings.editor.auto_signature_help = Some(true); + settings.editor.hover_popover_delay = Some(DelayMs(300)); }); }); }); diff --git a/crates/editor/src/signature_help.rs b/crates/editor/src/signature_help.rs index e88ede2909b4080dee90f6b8348f4676c23b5191..7781b0a740b70c25e44b337966d1de6bda31ced3 100644 --- a/crates/editor/src/signature_help.rs +++ b/crates/editor/src/signature_help.rs @@ -10,6 +10,7 @@ use markdown::{Markdown, MarkdownElement}; use multi_buffer::{Anchor, MultiBufferOffset, ToOffset}; use settings::Settings; use std::ops::Range; +use std::time::Duration; use text::Rope; use theme::ThemeSettings; use ui::{ @@ -170,6 +171,10 @@ impl Editor { return; } + // If there's an already running signature + // help task, this will drop it. + self.signature_help_state.task = None; + let position = self.selections.newest_anchor().head(); let Some((buffer, buffer_position)) = self.buffer.read(cx).text_anchor_for_position(position, cx) @@ -179,14 +184,23 @@ impl Editor { let Some(lsp_store) = self.project().map(|p| p.read(cx).lsp_store()) else { return; }; - let task = lsp_store.update(cx, |lsp_store, cx| { + let lsp_task = lsp_store.update(cx, |lsp_store, cx| { lsp_store.signature_help(&buffer, buffer_position, cx) }); let language = self.language_at(position, cx); + let signature_help_delay_ms = EditorSettings::get_global(cx).hover_popover_delay.0; + self.signature_help_state .set_task(cx.spawn_in(window, async move |editor, cx| { - let signature_help = task.await; + if signature_help_delay_ms > 0 { + cx.background_executor() + .timer(Duration::from_millis(signature_help_delay_ms)) + .await; + } + + let signature_help = lsp_task.await; + editor .update(cx, |editor, cx| { let Some(mut signature_help) =