Split diagnostics markdown style out (#29637)

Conrad Irwin created

Closes #29572

Release Notes:

- Fixed paragraph spacing in git commit messages

Change summary

crates/diagnostics/src/diagnostic_renderer.rs | 25 +++++----
crates/diagnostics/src/diagnostics.rs         |  3 
crates/editor/src/hover_popover.rs            | 52 ++++++++++++++++++++
3 files changed, 66 insertions(+), 14 deletions(-)

Detailed changes

crates/diagnostics/src/diagnostic_renderer.rs 🔗

@@ -3,7 +3,7 @@ use std::{ops::Range, sync::Arc};
 use editor::{
     Anchor, Editor, EditorSnapshot, ToOffset,
     display_map::{BlockContext, BlockPlacement, BlockProperties, BlockStyle},
-    hover_markdown_style,
+    hover_popover::diagnostics_markdown_style,
     scroll::Autoscroll,
 };
 use gpui::{AppContext, Entity, Focusable, WeakEntity};
@@ -215,16 +215,19 @@ impl DiagnosticBlock {
             .border_color(border_color)
             .max_w(max_width)
             .child(
-                MarkdownElement::new(self.markdown.clone(), hover_markdown_style(bcx.window, cx))
-                    .on_url_click({
-                        move |link, window, cx| {
-                            editor
-                                .update(cx, |editor, cx| {
-                                    Self::open_link(editor, &diagnostics_editor, link, window, cx)
-                                })
-                                .ok();
-                        }
-                    }),
+                MarkdownElement::new(
+                    self.markdown.clone(),
+                    diagnostics_markdown_style(bcx.window, cx),
+                )
+                .on_url_click({
+                    move |link, window, cx| {
+                        editor
+                            .update(cx, |editor, cx| {
+                                Self::open_link(editor, &diagnostics_editor, link, window, cx)
+                            })
+                            .ok();
+                    }
+                }),
             )
             .into_any_element()
     }

crates/diagnostics/src/diagnostics.rs 🔗

@@ -23,6 +23,7 @@ use language::{
     Bias, Buffer, BufferRow, BufferSnapshot, DiagnosticEntry, Point, ToTreeSitterPoint,
 };
 use lsp::DiagnosticSeverity;
+
 use project::{DiagnosticSummary, Project, ProjectPath, project_settings::ProjectSettings};
 use settings::Settings;
 use std::{
@@ -521,7 +522,7 @@ impl ProjectDiagnosticsEditor {
                                 markdown::MarkdownElement::rendered_text(
                                     markdown.clone(),
                                     cx,
-                                    editor::hover_markdown_style,
+                                    editor::hover_popover::diagnostics_markdown_style,
                                 )
                             },
                         );

crates/editor/src/hover_popover.rs 🔗

@@ -622,6 +622,55 @@ pub fn hover_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
     let buffer_font_family = settings.buffer_font.family.clone();
     let buffer_font_fallbacks = settings.buffer_font.fallbacks.clone();
 
+    let mut base_text_style = window.text_style();
+    base_text_style.refine(&TextStyleRefinement {
+        font_family: Some(ui_font_family.clone()),
+        font_fallbacks: ui_font_fallbacks,
+        color: Some(cx.theme().colors().editor_foreground),
+        ..Default::default()
+    });
+    MarkdownStyle {
+        base_text_style,
+        code_block: StyleRefinement::default().my(rems(1.)).font_buffer(cx),
+        inline_code: TextStyleRefinement {
+            background_color: Some(cx.theme().colors().background),
+            font_family: Some(buffer_font_family),
+            font_fallbacks: buffer_font_fallbacks,
+            ..Default::default()
+        },
+        rule_color: cx.theme().colors().border,
+        block_quote_border_color: Color::Muted.color(cx),
+        block_quote: TextStyleRefinement {
+            color: Some(Color::Muted.color(cx)),
+            ..Default::default()
+        },
+        link: TextStyleRefinement {
+            color: Some(cx.theme().colors().editor_foreground),
+            underline: Some(gpui::UnderlineStyle {
+                thickness: px(1.),
+                color: Some(cx.theme().colors().editor_foreground),
+                wavy: false,
+            }),
+            ..Default::default()
+        },
+        syntax: cx.theme().syntax().clone(),
+        selection_background_color: { cx.theme().players().local().selection },
+        heading: StyleRefinement::default()
+            .font_weight(FontWeight::BOLD)
+            .text_base()
+            .mt(rems(1.))
+            .mb_0(),
+        ..Default::default()
+    }
+}
+
+pub fn diagnostics_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
+    let settings = ThemeSettings::get_global(cx);
+    let ui_font_family = settings.ui_font.family.clone();
+    let ui_font_fallbacks = settings.ui_font.fallbacks.clone();
+    let buffer_font_family = settings.buffer_font.family.clone();
+    let buffer_font_fallbacks = settings.buffer_font.fallbacks.clone();
+
     let mut base_text_style = window.text_style();
     base_text_style.refine(&TextStyleRefinement {
         font_family: Some(ui_font_family.clone()),
@@ -659,7 +708,6 @@ pub fn hover_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
         heading: StyleRefinement::default()
             .font_weight(FontWeight::BOLD)
             .text_base()
-            .mt(rems(1.))
             .mb_0(),
         ..Default::default()
     }
@@ -951,7 +999,7 @@ impl DiagnosticPopover {
                     .child(
                         MarkdownElement::new(
                             self.markdown.clone(),
-                            hover_markdown_style(window, cx),
+                            diagnostics_markdown_style(window, cx),
                         )
                         .on_url_click(move |link, window, cx| {
                             if let Some(renderer) = GlobalDiagnosticRenderer::global(cx) {