Re-add diagnostic headers

This commit is contained in:
Nate Butler 2023-12-01 15:30:01 -05:00
parent f5679f98d6
commit 89aa6a3726
4 changed files with 67 additions and 23 deletions

1
assets/icons/copy.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-copy"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>

After

Width:  |  Height:  |  Size: 338 B

View File

@ -100,8 +100,8 @@ use text::{OffsetUtf16, Rope};
use theme::{
ActiveTheme, DiagnosticStyle, PlayerColor, SyntaxTheme, Theme, ThemeColors, ThemeSettings,
};
use ui::prelude::*;
use ui::{h_stack, v_stack, HighlightedLabel, IconButton, Popover, Tooltip};
use ui::{h_stack, v_stack, ButtonSize, HighlightedLabel, Icon, IconButton, Popover, Tooltip};
use ui::{prelude::*, IconSize};
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
use workspace::{
item::{ItemEvent, ItemHandle},
@ -9694,20 +9694,34 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
let message = diagnostic.message;
Arc::new(move |cx: &mut BlockContext| {
let message = message.clone();
let copy_id: SharedString = format!("copy-{}", cx.block_id.clone()).to_string().into();
let write_to_clipboard = cx.write_to_clipboard(ClipboardItem::new(message.clone()));
// 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
v_stack()
.id(cx.block_id)
.relative()
.size_full()
.bg(gpui::red())
.children(highlighted_lines.iter().map(|(line, highlights)| {
div()
h_stack()
.items_start()
.gap_2()
.elevation_2(cx)
.absolute()
.left(cx.anchor_x)
.px_1p5()
.py_0p5()
.child(HighlightedLabel::new(line.clone(), highlights.clone()))
.ml(cx.anchor_x)
.child(
IconButton::new(copy_id.clone(), Icon::Copy)
// .color(Color::Muted)
.size(ButtonSize::Compact)
.on_click(cx.listener(move |_, _, cx| write_to_clipboard))
.tooltip(|cx| Tooltip::text("Copy diagnostic message", cx)),
)
}))
.cursor_pointer()
.on_click(cx.listener(move |_, _, cx| {
cx.write_to_clipboard(ClipboardItem::new(message.clone()));
}))
.tooltip(|cx| Tooltip::text("Copy diagnostic message", cx))
.into_any_element()
})
}

View File

@ -51,8 +51,8 @@ use std::{
};
use sum_tree::Bias;
use theme::{ActiveTheme, PlayerColor};
use ui::prelude::*;
use ui::{h_stack, IconButton, Tooltip};
use ui::{h_stack, Disclosure, IconButton, IconSize, Label, Tooltip};
use ui::{prelude::*, Icon};
use util::ResultExt;
use workspace::item::Item;
@ -2234,7 +2234,7 @@ impl EditorElement {
.map_or(range.context.start, |primary| primary.start);
let jump_position = language::ToPoint::to_point(&jump_anchor, buffer);
IconButton::new(block_id, ui::Icon::ArrowUpRight)
IconButton::new(block_id, Icon::ArrowUpRight)
.on_click(cx.listener_for(&self.editor, move |editor, e, cx| {
editor.jump(jump_path.clone(), jump_position, jump_anchor, cx);
}))
@ -2253,17 +2253,44 @@ impl EditorElement {
.map(|p| SharedString::from(p.to_string_lossy().to_string() + "/"));
}
h_stack()
.id("path header block")
.size_full()
.bg(gpui::red())
.child(
filename
.map(SharedString::from)
.unwrap_or_else(|| "untitled".into()),
)
.children(parent_path)
.children(jump_icon) // .p_x(gutter_padding)
div().id("path header block").size_full().p_1p5().child(
h_stack()
.py_1p5()
.pl_3()
.pr_2()
.rounded_lg()
.shadow_md()
.border()
.border_color(cx.theme().colors().border)
.bg(cx.theme().colors().editor_subheader_background)
.justify_between()
.cursor_pointer()
.hover(|style| style.bg(cx.theme().colors().element_hover))
.child(
h_stack()
.gap_3()
// TODO: Add open/close state and toggle action
.child(
div()
.border()
.border_color(gpui::red())
.child(Disclosure::new(true)),
)
.child(
h_stack()
.gap_2()
.child(Label::new(
filename
.map(SharedString::from)
.unwrap_or_else(|| "untitled".into()),
))
.when_some(parent_path, |then, path| {
then.child(Label::new(path).color(Color::Muted))
}),
),
)
.children(jump_icon), // .p_x(gutter_padding)
)
} else {
let text_style = style.text.clone();
h_stack()

View File

@ -27,6 +27,7 @@ pub enum Icon {
Bolt,
CaseSensitive,
Check,
Copy,
ChevronDown,
ChevronLeft,
ChevronRight,
@ -99,6 +100,7 @@ impl Icon {
Icon::Bolt => "icons/bolt.svg",
Icon::CaseSensitive => "icons/case_insensitive.svg",
Icon::Check => "icons/check.svg",
Icon::Copy => "icons/copy.svg",
Icon::ChevronDown => "icons/chevron_down.svg",
Icon::ChevronLeft => "icons/chevron_left.svg",
Icon::ChevronRight => "icons/chevron_right.svg",