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,6 +769,9 @@ pub(crate) fn render_summary(
text_style: &TextStyle, text_style: &TextStyle,
theme: &theme::ProjectDiagnostics, theme: &theme::ProjectDiagnostics,
) -> ElementBox { ) -> ElementBox {
if summary.error_count == 0 && summary.warning_count == 0 {
Label::new("No problems".to_string(), text_style.clone()).boxed()
} else {
let icon_width = theme.tab_icon_width; let icon_width = theme.tab_icon_width;
let icon_spacing = theme.tab_icon_spacing; let icon_spacing = theme.tab_icon_spacing;
let summary_spacing = theme.tab_summary_spacing; let summary_spacing = theme.tab_summary_spacing;
@ -812,6 +814,7 @@ pub(crate) fn render_summary(
.boxed(), .boxed(),
]) ])
.boxed() .boxed()
}
} }
fn compare_diagnostics<L: language::ToOffset, R: language::ToOffset>( fn compare_diagnostics<L: language::ToOffset, R: language::ToOffset>(

View file

@ -3493,10 +3493,12 @@ 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;
if self.focused {
self.buffer.update(cx, |buffer, cx| { self.buffer.update(cx, |buffer, cx| {
buffer.set_active_selections(&self.selections, 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>) {
self.autoscroll_request = Some(autoscroll); self.autoscroll_request = Some(autoscroll);
@ -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

@ -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