Display filename on the first excerpt's header for a group

This commit is contained in:
Antonio Scandurra 2021-12-17 13:49:21 +01:00
parent 63f171200e
commit 3914d1d072
2 changed files with 19 additions and 7 deletions

View File

@ -113,8 +113,9 @@ impl ProjectDiagnosticsEditor {
let mut header = primary.clone();
header.message =
primary.message.split('\n').next().unwrap().to_string();
excerpt.header_height = 1;
excerpt.header_height = 2;
excerpt.render_header = Some(diagnostic_header_renderer(
buffer.clone(),
header,
self.build_settings.clone(),
));
@ -321,15 +322,16 @@ mod tests {
assert_eq!(
view.excerpts.read(cx).read(cx).text(),
concat!(
"\n",
"\n", // primary diagnostic message
"\n", // filename
" let x = vec![];\n",
" let y = vec![];\n",
" a(x);\n",
"\n",
"\n", // context ellipsis
" a(x);\n",
" b(y);\n",
" // comment 1\n",
"\n",
"\n", // context ellipsis
" // comment 3\n",
" // comment 4\n",
" d(y);"

View File

@ -14,7 +14,7 @@ use display_map::*;
pub use element::*;
use gpui::{
action,
elements::Text,
elements::*,
fonts::TextStyle,
geometry::vector::{vec2f, Vector2F},
keymap::Binding,
@ -3783,6 +3783,7 @@ pub fn diagnostic_block_renderer(
}
pub fn diagnostic_header_renderer(
buffer: ModelHandle<Buffer>,
diagnostic: Diagnostic,
build_settings: BuildSettings,
) -> RenderHeaderFn {
@ -3790,7 +3791,16 @@ pub fn diagnostic_header_renderer(
let settings = build_settings(cx);
let mut text_style = settings.style.text.clone();
text_style.color = diagnostic_style(diagnostic.severity, true, &settings.style).text;
Text::new(diagnostic.message.clone(), text_style).boxed()
let file_path = if let Some(file) = buffer.read(cx).file() {
file.path().to_string_lossy().to_string()
} else {
"untitled".to_string()
};
Flex::column()
.with_child(Label::new(diagnostic.message.clone(), text_style).boxed())
.with_child(Label::new(file_path, settings.style.text.clone()).boxed())
.boxed()
})
}
@ -3798,7 +3808,7 @@ pub fn context_header_renderer(build_settings: BuildSettings) -> RenderHeaderFn
Arc::new(move |cx| {
let settings = build_settings(cx);
let text_style = settings.style.text.clone();
Text::new("...".to_string(), text_style).boxed()
Label::new("...".to_string(), text_style).boxed()
})
}