Re-allow diagnostics hovers to soft wrap

Julia and Max Brunsfeld created

Co-Authored-By: Max Brunsfeld <max@zed.dev>

Change summary

crates/editor/src/hover_popover.rs   | 28 +++++++++++++---------------
crates/theme/src/theme.rs            |  2 +-
styles/src/styleTree/hoverPopover.ts |  2 +-
3 files changed, 15 insertions(+), 17 deletions(-)

Detailed changes

crates/editor/src/hover_popover.rs 🔗

@@ -1,7 +1,7 @@
 use futures::FutureExt;
 use gpui::{
     actions,
-    elements::{Flex, MouseEventHandler, Padding, ParentElement, Text},
+    elements::{Flex, MouseEventHandler, Padding, Text},
     impl_internal_actions,
     platform::{CursorStyle, MouseButton},
     AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext,
@@ -378,8 +378,17 @@ impl DiagnosticPopover {
 
         let mut text_style = style.hover_popover.prose.clone();
         text_style.font_size = style.text.font_size;
-        let mut diagnostic_source_style = style.hover_popover.diagnostic_source.clone();
-        diagnostic_source_style.font_size = style.text.font_size;
+        let diagnostic_source_style = style.hover_popover.diagnostic_source_highlight.clone();
+
+        let text = match &self.local_diagnostic.diagnostic.source {
+            Some(source) => Text::new(
+                format!("{source}: {}", self.local_diagnostic.diagnostic.message),
+                text_style,
+            )
+            .with_highlights(vec![(0..source.len(), diagnostic_source_style)]),
+
+            None => Text::new(self.local_diagnostic.diagnostic.message.clone(), text_style),
+        };
 
         let container_style = match self.local_diagnostic.diagnostic.severity {
             DiagnosticSeverity::HINT => style.hover_popover.info_container,
@@ -392,18 +401,7 @@ impl DiagnosticPopover {
         let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
 
         MouseEventHandler::<DiagnosticPopover, _>::new(0, cx, |_, _| {
-            Flex::row()
-                .with_children(
-                    self.local_diagnostic
-                        .diagnostic
-                        .source
-                        .as_ref()
-                        .map(|source| Text::new(format!("{source}: "), diagnostic_source_style)),
-                )
-                .with_child(
-                    Text::new(self.local_diagnostic.diagnostic.message.clone(), text_style)
-                        .with_soft_wrap(true),
-                )
+            text.with_soft_wrap(true)
                 .contained()
                 .with_style(container_style)
         })

crates/theme/src/theme.rs 🔗

@@ -887,7 +887,7 @@ pub struct HoverPopover {
     pub error_container: ContainerStyle,
     pub block_style: ContainerStyle,
     pub prose: TextStyle,
-    pub diagnostic_source: TextStyle,
+    pub diagnostic_source_highlight: HighlightStyle,
     pub highlight: Color,
 }
 

styles/src/styleTree/hoverPopover.ts 🔗

@@ -40,7 +40,7 @@ export default function HoverPopover(colorScheme: ColorScheme) {
             padding: { top: 4 },
         },
         prose: text(layer, "sans", { size: "sm" }),
-        diagnosticSource: text(layer, "sans", { size: "sm", underline: true, color: foreground(layer, "accent") }),
+        diagnosticSourceHighlight: { underline: true, color: foreground(layer, "accent") },
         highlight: colorScheme.ramps.neutral(0.5).alpha(0.2).hex(), // TODO: blend was used here. Replace with something better
     }
 }