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.

-
This commit is contained in:
Conrad Irwin 2025-06-04 10:33:22 -06:00 committed by GitHub
parent 7d54d9f45e
commit 2c5aa5891d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 1 deletions

View file

@ -639,6 +639,7 @@ pub struct HighlightedChunk<'a> {
pub text: &'a str, pub text: &'a str,
pub style: Option<HighlightStyle>, pub style: Option<HighlightStyle>,
pub is_tab: bool, pub is_tab: bool,
pub is_inlay: bool,
pub replacement: Option<ChunkReplacement>, pub replacement: Option<ChunkReplacement>,
} }
@ -652,6 +653,7 @@ impl<'a> HighlightedChunk<'a> {
let style = self.style; let style = self.style;
let is_tab = self.is_tab; let is_tab = self.is_tab;
let renderer = self.replacement; let renderer = self.replacement;
let is_inlay = self.is_inlay;
iter::from_fn(move || { iter::from_fn(move || {
let mut prefix_len = 0; let mut prefix_len = 0;
while let Some(&ch) = chars.peek() { while let Some(&ch) = chars.peek() {
@ -667,6 +669,7 @@ impl<'a> HighlightedChunk<'a> {
text: prefix, text: prefix,
style, style,
is_tab, is_tab,
is_inlay,
replacement: renderer.clone(), replacement: renderer.clone(),
}); });
} }
@ -693,6 +696,7 @@ impl<'a> HighlightedChunk<'a> {
text: prefix, text: prefix,
style: Some(invisible_style), style: Some(invisible_style),
is_tab: false, is_tab: false,
is_inlay,
replacement: Some(ChunkReplacement::Str(replacement.into())), replacement: Some(ChunkReplacement::Str(replacement.into())),
}); });
} else { } else {
@ -716,6 +720,7 @@ impl<'a> HighlightedChunk<'a> {
text: prefix, text: prefix,
style: Some(invisible_style), style: Some(invisible_style),
is_tab: false, is_tab: false,
is_inlay,
replacement: renderer.clone(), replacement: renderer.clone(),
}); });
} }
@ -728,6 +733,7 @@ impl<'a> HighlightedChunk<'a> {
text: remainder, text: remainder,
style, style,
is_tab, is_tab,
is_inlay,
replacement: renderer.clone(), replacement: renderer.clone(),
}) })
} else { } else {
@ -984,6 +990,7 @@ impl DisplaySnapshot {
text: chunk.text, text: chunk.text,
style: highlight_style, style: highlight_style,
is_tab: chunk.is_tab, is_tab: chunk.is_tab,
is_inlay: chunk.is_inlay,
replacement: chunk.renderer.map(ChunkReplacement::Renderer), replacement: chunk.renderer.map(ChunkReplacement::Renderer),
} }
.highlight_invisibles(editor_style) .highlight_invisibles(editor_style)

View file

@ -1259,6 +1259,8 @@ pub struct Chunk<'a> {
pub underline: bool, pub underline: bool,
/// Whether this chunk of text was originally a tab character. /// Whether this chunk of text was originally a tab character.
pub is_tab: bool, 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. /// An optional recipe for how the chunk should be presented.
pub renderer: Option<ChunkRenderer>, pub renderer: Option<ChunkRenderer>,
} }
@ -1424,6 +1426,7 @@ impl<'a> Iterator for FoldChunks<'a> {
diagnostic_severity: chunk.diagnostic_severity, diagnostic_severity: chunk.diagnostic_severity,
is_unnecessary: chunk.is_unnecessary, is_unnecessary: chunk.is_unnecessary,
is_tab: chunk.is_tab, is_tab: chunk.is_tab,
is_inlay: chunk.is_inlay,
underline: chunk.underline, underline: chunk.underline,
renderer: None, renderer: None,
}); });

View file

@ -336,6 +336,7 @@ impl<'a> Iterator for InlayChunks<'a> {
Chunk { Chunk {
text: chunk, text: chunk,
highlight_style, highlight_style,
is_inlay: true,
..Default::default() ..Default::default()
} }
} }

View file

@ -6871,6 +6871,7 @@ impl LineWithInvisibles {
text: "\n", text: "\n",
style: None, style: None,
is_tab: false, is_tab: false,
is_inlay: false,
replacement: None, replacement: None,
}]) { }]) {
if let Some(replacement) = highlighted_chunk.replacement { if let Some(replacement) = highlighted_chunk.replacement {
@ -7004,7 +7005,7 @@ impl LineWithInvisibles {
strikethrough: text_style.strikethrough, 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, // Line wrap pads its contents with fake whitespaces,
// avoid printing them // avoid printing them
let is_soft_wrapped = is_row_soft_wrapped(row); let is_soft_wrapped = is_row_soft_wrapped(row);

View file

@ -485,6 +485,8 @@ pub struct Chunk<'a> {
pub is_unnecessary: bool, pub is_unnecessary: bool,
/// Whether this chunk of text was originally a tab character. /// Whether this chunk of text was originally a tab character.
pub is_tab: bool, 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. /// Whether to underline the corresponding text range in the editor.
pub underline: bool, pub underline: bool,
} }