Fix rendering of diagnostic blocks (#4232)

- Distinct colors to make it not confusing
- Avoid overflowing the edge of the editor when the message is long


Release Notes:

- Improved display of diagnostic blocks (F8)
This commit is contained in:
Conrad Irwin 2024-01-23 16:39:57 -07:00 committed by GitHub
commit a3968c5cc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 9 deletions

View file

@ -1603,6 +1603,7 @@ mod tests {
gutter_width: px(0.), gutter_width: px(0.),
line_height: px(0.), line_height: px(0.),
em_width: px(0.), em_width: px(0.),
max_width: px(0.),
block_id: ix, block_id: ix,
view: editor_view, view: editor_view,
editor_style: &editor::EditorStyle::default(), editor_style: &editor::EditorStyle::default(),

View file

@ -84,6 +84,7 @@ pub struct BlockContext<'a, 'b> {
pub context: &'b mut ElementContext<'a>, pub context: &'b mut ElementContext<'a>,
pub view: View<Editor>, pub view: View<Editor>,
pub anchor_x: Pixels, pub anchor_x: Pixels,
pub max_width: Pixels,
pub gutter_width: Pixels, pub gutter_width: Pixels,
pub gutter_padding: Pixels, pub gutter_padding: Pixels,
pub em_width: Pixels, pub em_width: Pixels,

View file

@ -9593,31 +9593,33 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, _is_valid: bool) -> Ren
let (text_without_backticks, code_ranges) = highlight_diagnostic_message(&diagnostic); let (text_without_backticks, code_ranges) = highlight_diagnostic_message(&diagnostic);
Arc::new(move |cx: &mut BlockContext| { Arc::new(move |cx: &mut BlockContext| {
let color = Some(cx.theme().colors().text_accent);
let group_id: SharedString = cx.block_id.to_string().into(); let group_id: SharedString = cx.block_id.to_string().into();
// TODO: Nate: We should tint the background of the block with the severity color
// We need to extend the theme before we can do this let mut text_style = cx.text_style().clone();
text_style.color = diagnostic_style(diagnostic.severity, true, cx.theme().status());
h_flex() h_flex()
.id(cx.block_id) .id(cx.block_id)
.group(group_id.clone()) .group(group_id.clone())
.relative() .relative()
.pl(cx.anchor_x)
.size_full() .size_full()
.gap_2() .pl(cx.gutter_width)
.child( .w(cx.max_width + cx.gutter_width)
.child(div().flex().w(cx.anchor_x - cx.gutter_width).flex_shrink())
.child(div().flex().flex_shrink_0().child(
StyledText::new(text_without_backticks.clone()).with_highlights( StyledText::new(text_without_backticks.clone()).with_highlights(
&cx.text_style(), &text_style,
code_ranges.iter().map(|range| { code_ranges.iter().map(|range| {
( (
range.clone(), range.clone(),
HighlightStyle { HighlightStyle {
color, font_weight: Some(FontWeight::BOLD),
..Default::default() ..Default::default()
}, },
) )
}), }),
), ),
) ))
.child( .child(
IconButton::new(("copy-block", cx.block_id), IconName::Copy) IconButton::new(("copy-block", cx.block_id), IconName::Copy)
.icon_color(Color::Muted) .icon_color(Color::Muted)

View file

@ -2074,6 +2074,7 @@ impl EditorElement {
&snapshot, &snapshot,
bounds.size.width, bounds.size.width,
scroll_width, scroll_width,
text_width,
gutter_dimensions.padding, gutter_dimensions.padding,
gutter_dimensions.width, gutter_dimensions.width,
em_width, em_width,
@ -2260,6 +2261,7 @@ impl EditorElement {
snapshot: &EditorSnapshot, snapshot: &EditorSnapshot,
editor_width: Pixels, editor_width: Pixels,
scroll_width: Pixels, scroll_width: Pixels,
text_width: Pixels,
gutter_padding: Pixels, gutter_padding: Pixels,
gutter_width: Pixels, gutter_width: Pixels,
em_width: Pixels, em_width: Pixels,
@ -2309,6 +2311,7 @@ impl EditorElement {
gutter_width, gutter_width,
em_width, em_width,
block_id, block_id,
max_width: scroll_width.max(text_width),
view: editor_view.clone(), view: editor_view.clone(),
editor_style: &self.style, editor_style: &self.style,
}) })