Re-allow diagnostics hovers to soft wrap

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Julia 2023-04-26 13:21:19 -04:00
parent 3f7533a0b4
commit 678c188de0
3 changed files with 15 additions and 17 deletions

View File

@ -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)
})

View File

@ -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,
}

View File

@ -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
}
}