Render a "Jump to Buffer" icon on all excerpt headers

This commit is contained in:
Antonio Scandurra 2022-06-08 15:31:29 +02:00
parent c2eaf6128e
commit 712d47d94f
7 changed files with 86 additions and 74 deletions

View file

@ -9,13 +9,13 @@ use editor::{
ToOffset,
};
use gpui::{
actions, elements::*, fonts::TextStyle, impl_internal_actions, platform::CursorStyle,
serde_json, AnyViewHandle, AppContext, Entity, ModelHandle, MutableAppContext, RenderContext,
Task, View, ViewContext, ViewHandle, WeakViewHandle,
actions, elements::*, fonts::TextStyle, impl_internal_actions, serde_json, AnyViewHandle,
AppContext, Entity, ModelHandle, MutableAppContext, RenderContext, Task, View, ViewContext,
ViewHandle, WeakViewHandle,
};
use language::{
Anchor, Bias, Buffer, Diagnostic, DiagnosticEntry, DiagnosticSeverity, Point, Selection,
SelectionGoal, ToPoint,
SelectionGoal,
};
use project::{DiagnosticSummary, Project, ProjectPath};
use serde_json::json;
@ -342,20 +342,13 @@ impl ProjectDiagnosticsEditor {
is_first_excerpt_for_group = false;
let mut primary =
group.entries[group.primary_ix].diagnostic.clone();
let anchor = group.entries[group.primary_ix].range.start;
let position = anchor.to_point(&snapshot);
primary.message =
primary.message.split('\n').next().unwrap().to_string();
group_state.block_count += 1;
blocks_to_add.push(BlockProperties {
position: header_position,
height: 2,
render: diagnostic_header_renderer(
primary,
path.clone(),
position,
anchor,
),
render: diagnostic_header_renderer(primary),
disposition: BlockDisposition::Above,
});
}
@ -612,18 +605,10 @@ impl workspace::Item for ProjectDiagnosticsEditor {
}
}
fn diagnostic_header_renderer(
diagnostic: Diagnostic,
path: ProjectPath,
position: Point,
anchor: Anchor,
) -> RenderBlock {
enum JumpIcon {}
fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
let (message, highlights) = highlight_diagnostic_message(&diagnostic.message);
Arc::new(move |cx| {
let settings = cx.global::<Settings>();
let tooltip_style = settings.theme.tooltip.clone();
let theme = &settings.theme.editor;
let style = theme.diagnostic_header.clone();
let font_size = (style.text_scale_factor * settings.buffer_font_size).round();
@ -664,43 +649,6 @@ fn diagnostic_header_renderer(
.aligned()
.boxed()
}))
.with_child(
MouseEventHandler::new::<JumpIcon, _, _>(diagnostic.group_id, cx, |state, _| {
let style = style.jump_icon.style_for(state, false);
Svg::new("icons/jump.svg")
.with_color(style.color)
.constrained()
.with_width(style.icon_width)
.aligned()
.contained()
.with_style(style.container)
.constrained()
.with_width(style.button_width)
.with_height(style.button_width)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click({
let path = path.clone();
move |_, _, cx| {
cx.dispatch_action(Jump {
path: path.clone(),
position,
anchor,
});
}
})
.with_tooltip(
diagnostic.group_id,
"Jump to diagnostic".to_string(),
Some(Box::new(editor::OpenExcerpts)),
tooltip_style,
cx,
)
.aligned()
.flex_float()
.boxed(),
)
.contained()
.with_style(style.container)
.with_padding_left(x_padding)