Update block diagnostics (#28006)

Release Notes:

- "Block" diagnostics (that show up in the diagnostics view, or when
using `f8`/`shift-f8`) are rendered more clearly
- `f8`/`shift-f8` now always go to the "next" or "prev" diagnostic,
regardless of the state of the editor

![Screenshot 2025-04-09 at 16 42
09](https://github.com/user-attachments/assets/ae6d2ff6-5183-4b74-89d0-fefee1aa11e3)

---------

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Julia Ryan <juliaryan3.14@gmail.com>
This commit is contained in:
Conrad Irwin 2025-04-15 09:35:13 -06:00 committed by GitHub
parent ccf9aef767
commit afabcd1547
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 1794 additions and 1987 deletions

View file

@ -1,6 +1,7 @@
pub mod parser;
mod path_range;
use std::borrow::Cow;
use std::collections::HashSet;
use std::iter;
use std::mem;
@ -59,6 +60,7 @@ pub struct MarkdownStyle {
pub heading: StyleRefinement,
pub heading_level_styles: Option<HeadingLevelStyles>,
pub table_overflow_x_scroll: bool,
pub height_is_multiple_of_line_height: bool,
}
impl Default for MarkdownStyle {
@ -78,6 +80,7 @@ impl Default for MarkdownStyle {
heading: Default::default(),
heading_level_styles: None,
table_overflow_x_scroll: false,
height_is_multiple_of_line_height: false,
}
}
}
@ -205,6 +208,22 @@ impl Markdown {
&self.parsed_markdown
}
pub fn escape(s: &str) -> Cow<str> {
let count = s.bytes().filter(|c| c.is_ascii_punctuation()).count();
if count > 0 {
let mut output = String::with_capacity(s.len() + count);
for c in s.chars() {
if c.is_ascii_punctuation() {
output.push('\\')
}
output.push(c)
}
output.into()
} else {
s.into()
}
}
fn copy(&self, text: &RenderedText, _: &mut Window, cx: &mut Context<Self>) {
if self.selection.end <= self.selection.start {
return;
@ -367,6 +386,27 @@ impl MarkdownElement {
}
}
#[cfg(any(test, feature = "test-support"))]
pub fn rendered_text(
markdown: Entity<Markdown>,
cx: &mut gpui::VisualTestContext,
style: impl FnOnce(&Window, &App) -> MarkdownStyle,
) -> String {
use gpui::size;
let (text, _) = cx.draw(
Default::default(),
size(px(600.0), px(600.0)),
|window, cx| Self::new(markdown, style(window, cx)),
);
text.text
.lines
.iter()
.map(|line| line.layout.wrapped_text())
.collect::<Vec<_>>()
.join("\n")
}
pub fn code_block_renderer(mut self, variant: CodeBlockRenderer) -> Self {
self.code_block_renderer = variant;
self
@ -496,9 +536,9 @@ impl MarkdownElement {
pending: true,
};
window.focus(&markdown.focus_handle);
window.prevent_default();
}
window.prevent_default();
cx.notify();
}
} else if phase.capture() {
@ -634,7 +674,9 @@ impl Element for MarkdownElement {
match tag {
MarkdownTag::Paragraph => {
builder.push_div(
div().mb_2().line_height(rems(1.3)),
div().when(!self.style.height_is_multiple_of_line_height, |el| {
el.mb_2().line_height(rems(1.3))
}),
range,
markdown_end,
);
@ -767,11 +809,11 @@ impl Element for MarkdownElement {
};
builder.push_div(
div()
.mb_1()
.when(!self.style.height_is_multiple_of_line_height, |el| {
el.mb_1().gap_1().line_height(rems(1.3))
})
.h_flex()
.items_start()
.gap_1()
.line_height(rems(1.3))
.child(bullet),
range,
markdown_end,