Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Extend underlines into inlay hints (#56407)

Cameron Mcloughlin394f022be170
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs
index f7433c96448..143963a7f5e 100644
--- a/crates/editor/src/display_map.rs
+++ b/crates/editor/src/display_map.rs
@@ -1815,71 +1815,89 @@ impl DisplaySnapshot {
edit_prediction: Some(editor_style.edit_prediction_styles),
},
)
- .flat_map(|chunk| {
- let syntax_highlight_style = chunk
- .syntax_highlight_id
- .and_then(|id| editor_style.syntax.get(id).cloned());
-
- let chunk_highlight = chunk.highlight_style.map(|chunk_highlight| {
- HighlightStyle {
- // For color inlays, blend the color with the editor background
- // if the color has transparency (alpha < 1.0)
- color: chunk_highlight.color.map(|color| {
- if chunk.is_inlay && !color.is_opaque() {
- editor_style.background.blend(color)
- } else {
- color
- }
- }),
- underline: chunk_highlight
- .underline
- .filter(|_| editor_style.show_underlines),
- ..chunk_highlight
- }
- });
-
- let diagnostic_highlight = chunk
- .diagnostic_severity
- .filter(|severity| {
- self.diagnostics_max_severity
- .into_lsp()
- .is_some_and(|max_severity| severity <= &max_severity)
- })
- .map(|severity| HighlightStyle {
- fade_out: chunk
- .is_unnecessary
- .then_some(editor_style.unnecessary_code_fade),
- underline: (chunk.underline
- && editor_style.show_underlines
- && !(chunk.is_unnecessary && severity > lsp::DiagnosticSeverity::WARNING))
- .then(|| {
- let diagnostic_color = diagnostic_style(severity, &editor_style.status);
- UnderlineStyle {
- color: Some(diagnostic_color),
- thickness: 1.0.into(),
- wavy: true,
+ .flat_map({
+ // track the current underline style so that we can apply it to
+ // inlay hints within the diagnostic's span
+ let mut current_diagnostic_underline: Option<UnderlineStyle> = None;
+
+ move |chunk| {
+ let syntax_highlight_style = chunk
+ .syntax_highlight_id
+ .and_then(|id| editor_style.syntax.get(id).cloned());
+
+ let chunk_highlight = chunk.highlight_style.map(|chunk_highlight| {
+ HighlightStyle {
+ // For color inlays, blend the color with the editor background
+ // if the color has transparency (alpha < 1.0)
+ color: chunk_highlight.color.map(|color| {
+ if chunk.is_inlay && !color.is_opaque() {
+ editor_style.background.blend(color)
+ } else {
+ color
}
}),
- ..Default::default()
+ underline: chunk_highlight
+ .underline
+ .filter(|_| editor_style.show_underlines),
+ ..chunk_highlight
+ }
});
- let style = [
- syntax_highlight_style,
- chunk_highlight,
- diagnostic_highlight,
- ]
- .into_iter()
- .flatten()
- .reduce(|acc, highlight| acc.highlight(highlight));
+ let diagnostic_highlight = if chunk.is_inlay {
+ current_diagnostic_underline.map(|underline| HighlightStyle {
+ underline: Some(underline),
+ ..Default::default()
+ })
+ } else {
+ let highlight = chunk
+ .diagnostic_severity
+ .filter(|severity| {
+ self.diagnostics_max_severity
+ .into_lsp()
+ .is_some_and(|max_severity| severity <= &max_severity)
+ })
+ .map(|severity| HighlightStyle {
+ fade_out: chunk
+ .is_unnecessary
+ .then_some(editor_style.unnecessary_code_fade),
+ underline: (chunk.underline
+ && editor_style.show_underlines
+ && !(chunk.is_unnecessary
+ && severity > lsp::DiagnosticSeverity::WARNING))
+ .then(|| {
+ let diagnostic_color =
+ diagnostic_style(severity, &editor_style.status);
+ UnderlineStyle {
+ color: Some(diagnostic_color),
+ thickness: 1.0.into(),
+ wavy: true,
+ }
+ }),
+ ..Default::default()
+ });
- HighlightedChunk {
- text: chunk.text,
- style,
- is_tab: chunk.is_tab,
- is_inlay: chunk.is_inlay,
- replacement: chunk.renderer.map(ChunkReplacement::Renderer),
+ current_diagnostic_underline = highlight.as_ref().and_then(|h| h.underline);
+ highlight
+ };
+
+ let style = [
+ syntax_highlight_style,
+ chunk_highlight,
+ diagnostic_highlight,
+ ]
+ .into_iter()
+ .flatten()
+ .reduce(|acc, highlight| acc.highlight(highlight));
+
+ HighlightedChunk {
+ text: chunk.text,
+ style,
+ is_tab: chunk.is_tab,
+ is_inlay: chunk.is_inlay,
+ replacement: chunk.renderer.map(ChunkReplacement::Renderer),
+ }
+ .highlight_invisibles(editor_style)
}
- .highlight_invisibles(editor_style)
})
}