From 8dd1c23b92fa9b4a4330023a4f7f8edef831fa69 Mon Sep 17 00:00:00 2001 From: xzbdmw <97848247+xzbdmw@users.noreply.github.com> Date: Fri, 13 Dec 2024 07:37:58 +0800 Subject: [PATCH] editor: Add debounce setting for triggering DocumentHighlight (#21702) Closes https://github.com/zed-industries/zed/issues/6843 I don't see where is the logic to remove old document highlight when new one applies, ideally, old highlight should be cleared as soon as possible when cursor moves if the new position does not sits in old highlight ranges to avoid linger highlights described in https://github.com/zed-industries/zed/issues/13682#issuecomment-2498368680. So current solution is still not ideal, because only when lsp responses highlight ranges (even is a empty set) can we clear the old one. Release Notes: - Added a setting `lsp_highlight_debounce` to configure delay for querying highlights from language server. --------- Co-authored-by: mgsloan@gmail.com --- assets/settings/default.json | 3 +++ crates/editor/src/editor.rs | 6 ++---- crates/editor/src/editor_settings.rs | 6 ++++++ docs/src/configuring-zed.md | 6 ++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index a5ebc0d714..05b172a167 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -144,6 +144,9 @@ // 4. Highlight the full line (default): // "all" "current_line_highlight": "all", + // The debounce delay before querying highlights from the language + // server based on the current cursor location. + "lsp_highlight_debounce": 75, // Whether to pop the completions menu while typing in an editor without // explicitly requesting it. "show_completions_on_input": true, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 82558650ae..6dcd2c17a8 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -190,8 +190,6 @@ const MAX_SELECTION_HISTORY_LEN: usize = 1024; pub(crate) const CURSORS_VISIBLE_FOR: Duration = Duration::from_millis(2000); #[doc(hidden)] pub const CODE_ACTIONS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(250); -#[doc(hidden)] -pub const DOCUMENT_HIGHLIGHTS_DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75); pub(crate) const FORMAT_TIMEOUT: Duration = Duration::from_secs(2); pub(crate) const SCROLL_CENTER_TOP_BOTTOM_DEBOUNCE_TIMEOUT: Duration = Duration::from_secs(1); @@ -4311,10 +4309,10 @@ impl Editor { if cursor_buffer != tail_buffer { return None; } - + let debounce = EditorSettings::get_global(cx).lsp_highlight_debounce; self.document_highlights_task = Some(cx.spawn(|this, mut cx| async move { cx.background_executor() - .timer(DOCUMENT_HIGHLIGHTS_DEBOUNCE_TIMEOUT) + .timer(Duration::from_millis(debounce)) .await; let highlights = if let Some(highlights) = cx diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index b131fa5c21..27d78c8345 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -9,6 +9,7 @@ pub struct EditorSettings { pub cursor_blink: bool, pub cursor_shape: Option, pub current_line_highlight: CurrentLineHighlight, + pub lsp_highlight_debounce: u64, pub hover_popover_enabled: bool, pub toolbar: Toolbar, pub scrollbar: Scrollbar, @@ -185,6 +186,11 @@ pub struct EditorSettingsContent { /// /// Default: all pub current_line_highlight: Option, + /// The debounce delay before querying highlights from the language + /// server based on the current cursor location. + /// + /// Default: 75 + pub lsp_highlight_debounce: Option, /// Whether to show the informational hover box when moving the mouse /// over symbols in the editor. /// diff --git a/docs/src/configuring-zed.md b/docs/src/configuring-zed.md index 031be6b1ca..3aefae4c1f 100644 --- a/docs/src/configuring-zed.md +++ b/docs/src/configuring-zed.md @@ -467,6 +467,12 @@ List of `string` values "current_line_highlight": "all" ``` +## LSP Highlight Debounce + +- Description: The debounce delay before querying highlights from the language server based on the current cursor location. +- Setting: `lsp_highlight_debounce` +- Default: `75` + ## Cursor Blink - Description: Whether or not the cursor blinks.