From 8730bdcbdb7af7b6e2501aae1ae274292ba81da4 Mon Sep 17 00:00:00 2001 From: Alfie-Joe Smith Date: Wed, 17 Sep 2025 00:34:50 +0100 Subject: [PATCH 1/2] Always compute inlay hints --- helix-term/src/commands/lsp.rs | 8 ++---- helix-view/src/view.rs | 52 ++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 929774c7999d..8daee4cf1fcb 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1271,10 +1271,6 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) { } pub fn compute_inlay_hints_for_all_views(editor: &mut Editor, jobs: &mut crate::job::Jobs) { - if !editor.config().lsp.display_inlay_hints { - return; - } - for (view, _) in editor.tree.views() { let doc = match editor.documents.get(&view.doc) { Some(doc) => doc, @@ -1340,8 +1336,8 @@ fn compute_inlay_hints_for_view( let callback = super::make_job_callback( language_server.text_document_range_inlay_hints(doc.identifier(), range, None)?, move |editor, _compositor, response: Option>| { - // The config was modified or the window was closed while the request was in flight - if !editor.config().lsp.display_inlay_hints || editor.tree.try_get(view_id).is_none() { + // The window was closed while the request was in flight + if editor.tree.try_get(view_id).is_none() { return; } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index aecf09a610ed..c89c39cfe903 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -449,32 +449,36 @@ impl View { text_annotations.add_overlay(labels, style); } - if let Some(DocumentInlayHints { - id: _, - type_inlay_hints, - parameter_inlay_hints, - other_inlay_hints, - padding_before_inlay_hints, - padding_after_inlay_hints, - }) = doc.inlay_hints.get(&self.id) - { - let type_style = theme.and_then(|t| t.find_highlight("ui.virtual.inlay-hint.type")); - let parameter_style = - theme.and_then(|t| t.find_highlight("ui.virtual.inlay-hint.parameter")); - let other_style = theme.and_then(|t| t.find_highlight("ui.virtual.inlay-hint")); - - // Overlapping annotations are ignored apart from the first so the order here is not random: - // types -> parameters -> others should hopefully be the "correct" order for most use cases, - // with the padding coming before and after as expected. - text_annotations - .add_inline_annotations(padding_before_inlay_hints, None) - .add_inline_annotations(type_inlay_hints, type_style) - .add_inline_annotations(parameter_inlay_hints, parameter_style) - .add_inline_annotations(other_inlay_hints, other_style) - .add_inline_annotations(padding_after_inlay_hints, None); - }; let config = doc.config.load(); + // Only render the inlay hints if the config has them enabled + if config.lsp.display_inlay_hints { + if let Some(DocumentInlayHints { + id: _, + type_inlay_hints, + parameter_inlay_hints, + other_inlay_hints, + padding_before_inlay_hints, + padding_after_inlay_hints, + }) = doc.inlay_hints.get(&self.id) + { + let type_style = theme.and_then(|t| t.find_highlight("ui.virtual.inlay-hint.type")); + let parameter_style = + theme.and_then(|t| t.find_highlight("ui.virtual.inlay-hint.parameter")); + let other_style = theme.and_then(|t| t.find_highlight("ui.virtual.inlay-hint")); + + // Overlapping annotations are ignored apart from the first so the order here is not random: + // types -> parameters -> others should hopefully be the "correct" order for most use cases, + // with the padding coming before and after as expected. + text_annotations + .add_inline_annotations(padding_before_inlay_hints, None) + .add_inline_annotations(type_inlay_hints, type_style) + .add_inline_annotations(parameter_inlay_hints, parameter_style) + .add_inline_annotations(other_inlay_hints, other_style) + .add_inline_annotations(padding_after_inlay_hints, None); + }; + } + if config.lsp.display_color_swatches { if let Some(DocumentColorSwatches { color_swatches, From 6df4dfbd8b83095e979c8e5ac95f84af6c6542e1 Mon Sep 17 00:00:00 2001 From: Alfie-Joe Smith Date: Sat, 20 Sep 2025 14:12:32 +0100 Subject: [PATCH 2/2] Add display lsp config setting --- book/src/editor.md | 2 +- helix-term/src/commands/lsp.rs | 12 +++++++++--- helix-view/src/editor.rs | 20 +++++++++++++++++--- helix-view/src/view.rs | 4 ++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/book/src/editor.md b/book/src/editor.md index a9ea219b365c..958801cc3aee 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -161,7 +161,7 @@ The following statusline elements can be configured: | `display-messages` | Display LSP `window/showMessage` messages below statusline[^1] | `true` | | `display-progress-messages` | Display LSP progress messages below statusline[^1] | `false` | | `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` | -| `display-inlay-hints` | Display inlay hints[^2] | `false` | +| `display-inlay-hints` | Display inlay hints[^2] | `off` | | `inlay-hints-length-limit` | Maximum displayed length (non-zero number) of inlay hints | Unset by default | | `display-color-swatches` | Show color swatches next to colors | `true` | | `display-signature-help-docs` | Display docs under signature help popup | `true` | diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 8daee4cf1fcb..bade7a5970c1 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -20,7 +20,7 @@ use helix_core::{ use helix_stdx::path; use helix_view::{ document::{DocumentInlayHints, DocumentInlayHintsId}, - editor::Action, + editor::{Action, DisplayInlayHints}, handlers::lsp::SignatureHelpInvoked, theme::Style, Document, View, @@ -1271,6 +1271,10 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) { } pub fn compute_inlay_hints_for_all_views(editor: &mut Editor, jobs: &mut crate::job::Jobs) { + if let DisplayInlayHints::Off = editor.config().lsp.display_inlay_hints { + return; + } + for (view, _) in editor.tree.views() { let doc = match editor.documents.get(&view.doc) { Some(doc) => doc, @@ -1336,8 +1340,10 @@ fn compute_inlay_hints_for_view( let callback = super::make_job_callback( language_server.text_document_range_inlay_hints(doc.identifier(), range, None)?, move |editor, _compositor, response: Option>| { - // The window was closed while the request was in flight - if editor.tree.try_get(view_id).is_none() { + // The config was modified or the window was closed while the request was in flight + if editor.config().lsp.display_inlay_hints == DisplayInlayHints::Off + || editor.tree.try_get(view_id).is_none() + { return; } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 162d2b1f1c44..c12c9fa5b13e 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -477,7 +477,7 @@ pub struct LspConfig { /// Display docs under signature help popup pub display_signature_help_docs: bool, /// Display inlay hints - pub display_inlay_hints: bool, + pub display_inlay_hints: DisplayInlayHints, /// Maximum displayed length of inlay hints (excluding the added trailing `…`). /// If it's `None`, there's no limit pub inlay_hints_length_limit: Option, @@ -497,7 +497,7 @@ impl Default for LspConfig { display_messages: true, auto_signature_help: true, display_signature_help_docs: true, - display_inlay_hints: false, + display_inlay_hints: DisplayInlayHints::default(), inlay_hints_length_limit: None, snippets: true, goto_reference_include_declaration: true, @@ -506,6 +506,20 @@ impl Default for LspConfig { } } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +pub enum DisplayInlayHints { + Off, + On, + Background, +} + +impl Default for DisplayInlayHints { + fn default() -> Self { + Self::Off + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "kebab-case", default, deny_unknown_fields)] pub struct SearchConfig { @@ -1634,7 +1648,7 @@ impl Editor { // We can't simply check this config when rendering because inlay hints are only parts of // the possible annotations, and others could still be active, so we need to selectively // drop the inlay hints. - if !config.lsp.display_inlay_hints { + if config.lsp.display_inlay_hints != DisplayInlayHints::Off { for doc in self.documents_mut() { doc.reset_all_inlay_hints(); } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index c89c39cfe903..cc6965bf8446 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -2,7 +2,7 @@ use crate::{ align_view, annotations::diagnostics::InlineDiagnostics, document::{DocumentColorSwatches, DocumentInlayHints}, - editor::{GutterConfig, GutterType}, + editor::{DisplayInlayHints, GutterConfig, GutterType}, graphics::Rect, handlers::diagnostics::DiagnosticsHandler, Align, Document, DocumentId, Theme, ViewId, @@ -452,7 +452,7 @@ impl View { let config = doc.config.load(); // Only render the inlay hints if the config has them enabled - if config.lsp.display_inlay_hints { + if config.lsp.display_inlay_hints == DisplayInlayHints::On { if let Some(DocumentInlayHints { id: _, type_inlay_hints,