Merge pull request #375 from zed-industries/more-project-diagnostics-styling

Last touches on project diagnostics for now
This commit is contained in:
Antonio Scandurra 2022-01-27 16:47:05 +01:00 committed by GitHub
commit dbf48d2a5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 60 deletions

View file

@ -103,7 +103,7 @@ impl View for ProjectDiagnosticsEditor {
if self.path_states.is_empty() { if self.path_states.is_empty() {
let theme = &self.settings.borrow().theme.project_diagnostics; let theme = &self.settings.borrow().theme.project_diagnostics;
Label::new( Label::new(
"No problems detected in the project".to_string(), "No problems in workspace".to_string(),
theme.empty_message.clone(), theme.empty_message.clone(),
) )
.aligned() .aligned()
@ -132,10 +132,8 @@ impl ProjectDiagnosticsEditor {
let project = model.read(cx).project.clone(); let project = model.read(cx).project.clone();
cx.subscribe(&project, |this, _, event, cx| match event { cx.subscribe(&project, |this, _, event, cx| match event {
project::Event::DiskBasedDiagnosticsFinished => { project::Event::DiskBasedDiagnosticsFinished => {
this.summary = this.model.read(cx).project.read(cx).diagnostic_summary(cx); this.update_excerpts(cx);
let paths = mem::take(&mut this.paths_to_update); this.update_title(cx);
this.update_excerpts(paths, cx);
cx.emit(Event::TitleChanged);
} }
project::Event::DiagnosticsUpdated(path) => { project::Event::DiagnosticsUpdated(path) => {
this.paths_to_update.insert(path.clone()); this.paths_to_update.insert(path.clone());
@ -156,7 +154,7 @@ impl ProjectDiagnosticsEditor {
let project = project.read(cx); let project = project.read(cx);
let paths_to_update = project.diagnostic_summaries(cx).map(|e| e.0).collect(); let paths_to_update = project.diagnostic_summaries(cx).map(|e| e.0).collect();
let this = Self { let mut this = Self {
model, model,
summary: project.diagnostic_summary(cx), summary: project.diagnostic_summary(cx),
workspace, workspace,
@ -165,9 +163,9 @@ impl ProjectDiagnosticsEditor {
build_settings, build_settings,
settings, settings,
path_states: Default::default(), path_states: Default::default(),
paths_to_update: Default::default(), paths_to_update,
}; };
this.update_excerpts(paths_to_update, cx); this.update_excerpts(cx);
this this
} }
@ -222,7 +220,8 @@ impl ProjectDiagnosticsEditor {
} }
} }
fn update_excerpts(&self, paths: BTreeSet<ProjectPath>, cx: &mut ViewContext<Self>) { fn update_excerpts(&mut self, cx: &mut ViewContext<Self>) {
let paths = mem::take(&mut self.paths_to_update);
let project = self.model.read(cx).project.clone(); let project = self.model.read(cx).project.clone();
cx.spawn(|this, mut cx| { cx.spawn(|this, mut cx| {
async move { async move {
@ -280,12 +279,7 @@ impl ProjectDiagnosticsEditor {
let mut first_excerpt_id = None; let mut first_excerpt_id = None;
let excerpts_snapshot = self.excerpts.update(cx, |excerpts, excerpts_cx| { let excerpts_snapshot = self.excerpts.update(cx, |excerpts, excerpts_cx| {
let mut old_groups = path_state.diagnostic_groups.iter().enumerate().peekable(); let mut old_groups = path_state.diagnostic_groups.iter().enumerate().peekable();
let mut new_groups = snapshot let mut new_groups = snapshot.diagnostic_groups().into_iter().peekable();
.diagnostic_groups()
.into_iter()
.filter(|group| group.entries[group.primary_ix].diagnostic.is_disk_based)
.peekable();
loop { loop {
let mut to_insert = None; let mut to_insert = None;
let mut to_remove = None; let mut to_remove = None;
@ -526,6 +520,11 @@ impl ProjectDiagnosticsEditor {
} }
cx.notify(); cx.notify();
} }
fn update_title(&mut self, cx: &mut ViewContext<Self>) {
self.summary = self.model.read(cx).project.read(cx).diagnostic_summary(cx);
cx.emit(Event::TitleChanged);
}
} }
impl workspace::Item for ProjectDiagnostics { impl workspace::Item for ProjectDiagnostics {
@ -770,48 +769,52 @@ pub(crate) fn render_summary(
text_style: &TextStyle, text_style: &TextStyle,
theme: &theme::ProjectDiagnostics, theme: &theme::ProjectDiagnostics,
) -> ElementBox { ) -> ElementBox {
let icon_width = theme.tab_icon_width; if summary.error_count == 0 && summary.warning_count == 0 {
let icon_spacing = theme.tab_icon_spacing; Label::new("No problems".to_string(), text_style.clone()).boxed()
let summary_spacing = theme.tab_summary_spacing; } else {
Flex::row() let icon_width = theme.tab_icon_width;
.with_children([ let icon_spacing = theme.tab_icon_spacing;
Svg::new("icons/diagnostic-summary-error.svg") let summary_spacing = theme.tab_summary_spacing;
.with_color(text_style.color) Flex::row()
.constrained() .with_children([
.with_width(icon_width) Svg::new("icons/diagnostic-summary-error.svg")
.with_color(text_style.color)
.constrained()
.with_width(icon_width)
.aligned()
.contained()
.with_margin_right(icon_spacing)
.named("no-icon"),
Label::new(
summary.error_count.to_string(),
LabelStyle {
text: text_style.clone(),
highlight_text: None,
},
)
.aligned() .aligned()
.contained() .boxed(),
.with_margin_right(icon_spacing) Svg::new("icons/diagnostic-summary-warning.svg")
.named("no-icon"), .with_color(text_style.color)
Label::new( .constrained()
summary.error_count.to_string(), .with_width(icon_width)
LabelStyle { .aligned()
text: text_style.clone(), .contained()
highlight_text: None, .with_margin_left(summary_spacing)
}, .with_margin_right(icon_spacing)
) .named("warn-icon"),
.aligned() Label::new(
.boxed(), summary.warning_count.to_string(),
Svg::new("icons/diagnostic-summary-warning.svg") LabelStyle {
.with_color(text_style.color) text: text_style.clone(),
.constrained() highlight_text: None,
.with_width(icon_width) },
)
.aligned() .aligned()
.contained() .boxed(),
.with_margin_left(summary_spacing) ])
.with_margin_right(icon_spacing) .boxed()
.named("warn-icon"), }
Label::new(
summary.warning_count.to_string(),
LabelStyle {
text: text_style.clone(),
highlight_text: None,
},
)
.aligned()
.boxed(),
])
.boxed()
} }
fn compare_diagnostics<L: language::ToOffset, R: language::ToOffset>( fn compare_diagnostics<L: language::ToOffset, R: language::ToOffset>(

View file

@ -3493,9 +3493,11 @@ impl Editor {
fn set_selections(&mut self, selections: Arc<[Selection<Anchor>]>, cx: &mut ViewContext<Self>) { fn set_selections(&mut self, selections: Arc<[Selection<Anchor>]>, cx: &mut ViewContext<Self>) {
self.selections = selections; self.selections = selections;
self.buffer.update(cx, |buffer, cx| { if self.focused {
buffer.set_active_selections(&self.selections, cx) self.buffer.update(cx, |buffer, cx| {
}); buffer.set_active_selections(&self.selections, cx)
});
}
} }
pub fn request_autoscroll(&mut self, autoscroll: Autoscroll, cx: &mut ViewContext<Self>) { pub fn request_autoscroll(&mut self, autoscroll: Autoscroll, cx: &mut ViewContext<Self>) {
@ -3725,6 +3727,10 @@ impl Editor {
} }
fn pause_cursor_blinking(&mut self, cx: &mut ViewContext<Self>) { fn pause_cursor_blinking(&mut self, cx: &mut ViewContext<Self>) {
if !self.focused {
return;
}
self.show_local_cursors = true; self.show_local_cursors = true;
cx.notify(); cx.notify();

View file

@ -185,7 +185,7 @@ corner_radius = 6
[project_panel] [project_panel]
extends = "$panel" extends = "$panel"
padding.top = 6 # ($workspace.tab.height - $project_panel.entry.height) / 2 padding.top = 6 # ($workspace.tab.height - $project_panel.entry.height) / 2
[project_panel.entry] [project_panel.entry]
text = "$text.1" text = "$text.1"
@ -313,7 +313,7 @@ message.highlight_text.color = "$text.3.color"
[project_diagnostics] [project_diagnostics]
background = "$surface.1" background = "$surface.1"
empty_message = "$text.0" empty_message = { extends = "$text.0", size = 18 }
status_bar_item = { extends = "$text.2", margin.right = 10 } status_bar_item = { extends = "$text.2", margin.right = 10 }
tab_icon_width = 13 tab_icon_width = 13
tab_icon_spacing = 4 tab_icon_spacing = 4