From 678c188de0e3572e7d9f0e7ed388455ed057a1c4 Mon Sep 17 00:00:00 2001 From: Julia Date: Wed, 26 Apr 2023 13:21:19 -0400 Subject: [PATCH] Re-allow diagnostics hovers to soft wrap Co-Authored-By: Max Brunsfeld --- 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(-) diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index df2570a8ef4daad1ce2a2ef624553d20c03257a6..b45cdb6b017a7b87ae02f6ab903458861ed94057 100644 --- a/crates/editor/src/hover_popover.rs +++ b/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::().theme.tooltip.clone(); MouseEventHandler::::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) }) diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 6edf69d0541393681f61e786a6fdbbd49293422a..5f0e89b5bf9d26cd51209ad38da9f3e31676eb1f 100644 --- a/crates/theme/src/theme.rs +++ b/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, } diff --git a/styles/src/styleTree/hoverPopover.ts b/styles/src/styleTree/hoverPopover.ts index 31e1d807788e0d30ed03a498be27f73c86c08e90..fadd62db1d4cc1732a14b4459f2c3eea28891e71 100644 --- a/styles/src/styleTree/hoverPopover.ts +++ b/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 } }