From 2c5aa5891da85934c9002e8ee3d3c740ecc10d22 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 4 Jun 2025 10:33:22 -0600 Subject: [PATCH] Don't show invisibles from inlays (#32088) Closes #24266 Release Notes: - Whitespace added by inlay hints is no longer shown when `"show_whitespaces": "all"` is used. - --- crates/editor/src/display_map.rs | 7 +++++++ crates/editor/src/display_map/fold_map.rs | 3 +++ crates/editor/src/display_map/inlay_map.rs | 1 + crates/editor/src/element.rs | 3 ++- crates/language/src/buffer.rs | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 67eea53849..a9af8f2ff9 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -639,6 +639,7 @@ pub struct HighlightedChunk<'a> { pub text: &'a str, pub style: Option, pub is_tab: bool, + pub is_inlay: bool, pub replacement: Option, } @@ -652,6 +653,7 @@ impl<'a> HighlightedChunk<'a> { let style = self.style; let is_tab = self.is_tab; let renderer = self.replacement; + let is_inlay = self.is_inlay; iter::from_fn(move || { let mut prefix_len = 0; while let Some(&ch) = chars.peek() { @@ -667,6 +669,7 @@ impl<'a> HighlightedChunk<'a> { text: prefix, style, is_tab, + is_inlay, replacement: renderer.clone(), }); } @@ -693,6 +696,7 @@ impl<'a> HighlightedChunk<'a> { text: prefix, style: Some(invisible_style), is_tab: false, + is_inlay, replacement: Some(ChunkReplacement::Str(replacement.into())), }); } else { @@ -716,6 +720,7 @@ impl<'a> HighlightedChunk<'a> { text: prefix, style: Some(invisible_style), is_tab: false, + is_inlay, replacement: renderer.clone(), }); } @@ -728,6 +733,7 @@ impl<'a> HighlightedChunk<'a> { text: remainder, style, is_tab, + is_inlay, replacement: renderer.clone(), }) } else { @@ -984,6 +990,7 @@ impl DisplaySnapshot { text: chunk.text, style: highlight_style, is_tab: chunk.is_tab, + is_inlay: chunk.is_inlay, replacement: chunk.renderer.map(ChunkReplacement::Renderer), } .highlight_invisibles(editor_style) diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index e9a611d390..0011f07fea 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -1259,6 +1259,8 @@ pub struct Chunk<'a> { pub underline: bool, /// Whether this chunk of text was originally a tab character. pub is_tab: bool, + /// Whether this chunk of text was originally a tab character. + pub is_inlay: bool, /// An optional recipe for how the chunk should be presented. pub renderer: Option, } @@ -1424,6 +1426,7 @@ impl<'a> Iterator for FoldChunks<'a> { diagnostic_severity: chunk.diagnostic_severity, is_unnecessary: chunk.is_unnecessary, is_tab: chunk.is_tab, + is_inlay: chunk.is_inlay, underline: chunk.underline, renderer: None, }); diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index ec3bc4865c..3ec0084775 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -336,6 +336,7 @@ impl<'a> Iterator for InlayChunks<'a> { Chunk { text: chunk, highlight_style, + is_inlay: true, ..Default::default() } } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 53f72ac929..abe0f6aa7b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -6871,6 +6871,7 @@ impl LineWithInvisibles { text: "\n", style: None, is_tab: false, + is_inlay: false, replacement: None, }]) { if let Some(replacement) = highlighted_chunk.replacement { @@ -7004,7 +7005,7 @@ impl LineWithInvisibles { strikethrough: text_style.strikethrough, }); - if editor_mode.is_full() { + if editor_mode.is_full() && !highlighted_chunk.is_inlay { // Line wrap pads its contents with fake whitespaces, // avoid printing them let is_soft_wrapped = is_row_soft_wrapped(row); diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index ef7a22d7e7..8c02eb5b44 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -485,6 +485,8 @@ pub struct Chunk<'a> { pub is_unnecessary: bool, /// Whether this chunk of text was originally a tab character. pub is_tab: bool, + /// Whether this chunk of text was originally a tab character. + pub is_inlay: bool, /// Whether to underline the corresponding text range in the editor. pub underline: bool, }