From f7de0ad8ae3b17a148f7c460491edbcfe67c9dcf Mon Sep 17 00:00:00 2001 From: Julia Date: Mon, 1 May 2023 16:48:27 -0400 Subject: [PATCH 1/2] Show diagnostic source in diagnostic multibuffer headers --- crates/diagnostics/src/diagnostics.rs | 13 +++++++++++-- crates/theme/src/theme.rs | 1 + styles/src/styleTree/editor.ts | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 6973d83f9b0a351e2d1b294829c89b34f7acdd03..22f67265ecc2fec017938cba5e0e6e335da7fb91 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -697,8 +697,18 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { icon.constrained() .with_width(icon_width) .aligned() - .contained(), + .contained() + .with_margin_right(cx.gutter_padding), ) + .with_children(diagnostic.source.as_ref().map(|source| { + Label::new( + format!("{source}: "), + style.source.label.clone().with_font_size(font_size), + ) + .contained() + .with_style(style.message.container) + .aligned() + })) .with_child( Label::new( message.clone(), @@ -707,7 +717,6 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { .with_highlights(highlights.clone()) .contained() .with_style(style.message.container) - .with_margin_left(cx.gutter_padding) .aligned(), ) .with_children(diagnostic.code.clone().map(|code| { diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index d2962847729f75e580a95a39d29a0ef979ba26f5..1211f5374227617da02efe73f808e6dbee487e90 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -659,6 +659,7 @@ pub struct DiagnosticPathHeader { pub struct DiagnosticHeader { #[serde(flatten)] pub container: ContainerStyle, + pub source: ContainedLabel, pub message: ContainedLabel, pub code: ContainedText, pub text_scale_factor: f32, diff --git a/styles/src/styleTree/editor.ts b/styles/src/styleTree/editor.ts index 84ef51406ea17e97ee3cdb91017043794130e228..cd0adf6bc7f830a3633a335733aa4193553355f4 100644 --- a/styles/src/styleTree/editor.ts +++ b/styles/src/styleTree/editor.ts @@ -176,6 +176,9 @@ export default function editor(colorScheme: ColorScheme) { left: 10, }, }, + source: { + text: text(colorScheme.middle, "sans", { size: "sm", weight: "bold", }), + }, message: { highlightText: text(colorScheme.middle, "sans", { size: "sm", From 185c1650df6fef9cdc33da9d5b8791c3abf2c32b Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 2 May 2023 09:08:07 -0400 Subject: [PATCH 2/2] Show diagnostic source in inline diagnostic --- crates/diagnostics/src/diagnostics.rs | 2 +- crates/editor/src/editor.rs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 22f67265ecc2fec017938cba5e0e6e335da7fb91..17d142ba4b1bf869021475178db439e76c12a510 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -677,7 +677,7 @@ impl Item for ProjectDiagnosticsEditor { } fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { - let (message, highlights) = highlight_diagnostic_message(&diagnostic.message); + let (message, highlights) = highlight_diagnostic_message(Vec::new(), &diagnostic.message); Arc::new(move |cx| { let settings = cx.global::(); let theme = &settings.theme.editor; diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0849c0ef93525ef13ad7c16725d77272f6287ecc..df2ca6f43d8b67d9e206cdbfaf8eb817ac89725d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -7509,8 +7509,16 @@ impl Deref for EditorStyle { pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> RenderBlock { let mut highlighted_lines = Vec::new(); - for line in diagnostic.message.lines() { - highlighted_lines.push(highlight_diagnostic_message(line)); + for (index, line) in diagnostic.message.lines().enumerate() { + let line = match &diagnostic.source { + Some(source) if index == 0 => { + let source_highlight = Vec::from_iter(0..source.len()); + highlight_diagnostic_message(source_highlight, &format!("{source}: {line}")) + } + + _ => highlight_diagnostic_message(Vec::new(), line), + }; + highlighted_lines.push(line); } Arc::new(move |cx: &mut BlockContext| { @@ -7534,11 +7542,14 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend }) } -pub fn highlight_diagnostic_message(message: &str) -> (String, Vec) { +pub fn highlight_diagnostic_message( + inital_highlights: Vec, + message: &str, +) -> (String, Vec) { let mut message_without_backticks = String::new(); let mut prev_offset = 0; let mut inside_block = false; - let mut highlights = Vec::new(); + let mut highlights = inital_highlights; for (match_ix, (offset, _)) in message .match_indices('`') .chain([(message.len(), "")])