Display a "Checking..." message when running disk-based diagnostics

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-01-07 15:03:19 +01:00
parent e39be35e17
commit cf62d26ed8
6 changed files with 195 additions and 55 deletions

View file

@ -33,6 +33,7 @@ pub struct Project {
client_state: ProjectClientState,
collaborators: HashMap<PeerId, Collaborator>,
subscriptions: Vec<client::Subscription>,
pending_disk_based_diagnostics: isize,
}
enum ProjectClientState {
@ -60,7 +61,9 @@ pub struct Collaborator {
pub enum Event {
ActiveEntryChanged(Option<ProjectEntry>),
WorktreeRemoved(WorktreeId),
DiskBasedDiagnosticsStarted,
DiskBasedDiagnosticsUpdated { worktree_id: WorktreeId },
DiskBasedDiagnosticsFinished,
DiagnosticsUpdated(ProjectPath),
}
@ -187,6 +190,7 @@ impl Project {
client,
user_store,
fs,
pending_disk_based_diagnostics: 0,
}
})
}
@ -259,6 +263,11 @@ impl Project {
cx,
Self::handle_update_diagnostic_summary,
),
client.subscribe_to_entity(
remote_id,
cx,
Self::handle_disk_based_diagnostics_updating,
),
client.subscribe_to_entity(
remote_id,
cx,
@ -273,6 +282,7 @@ impl Project {
remote_id,
replica_id,
},
pending_disk_based_diagnostics: 0,
};
for worktree in worktrees {
this.add_worktree(worktree, cx);
@ -506,17 +516,29 @@ impl Project {
fn add_worktree(&mut self, worktree: ModelHandle<Worktree>, cx: &mut ModelContext<Self>) {
cx.observe(&worktree, |_, _, cx| cx.notify()).detach();
cx.subscribe(&worktree, |_, worktree, event, cx| match event {
cx.subscribe(&worktree, move |this, worktree, event, cx| match event {
worktree::Event::DiagnosticsUpdated(path) => {
cx.emit(Event::DiagnosticsUpdated(ProjectPath {
worktree_id: worktree.read(cx).id(),
path: path.clone(),
}));
}
worktree::Event::DiskBasedDiagnosticsUpdating => {
if this.pending_disk_based_diagnostics == 0 {
cx.emit(Event::DiskBasedDiagnosticsStarted);
}
this.pending_disk_based_diagnostics += 1;
}
worktree::Event::DiskBasedDiagnosticsUpdated => {
this.pending_disk_based_diagnostics -= 1;
cx.emit(Event::DiskBasedDiagnosticsUpdated {
worktree_id: worktree.read(cx).id(),
});
if this.pending_disk_based_diagnostics == 0 {
if this.pending_disk_based_diagnostics == 0 {
cx.emit(Event::DiskBasedDiagnosticsFinished);
}
}
}
})
.detach();
@ -539,6 +561,10 @@ impl Project {
}
}
pub fn is_running_disk_based_diagnostics(&self) -> bool {
self.pending_disk_based_diagnostics > 0
}
pub fn diagnostic_summary(&self, cx: &AppContext) -> DiagnosticSummary {
let mut summary = DiagnosticSummary::default();
for (_, path_summary) in self.diagnostic_summaries(cx) {
@ -716,6 +742,24 @@ impl Project {
Ok(())
}
fn handle_disk_based_diagnostics_updating(
&mut self,
envelope: TypedEnvelope<proto::DiskBasedDiagnosticsUpdating>,
_: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Result<()> {
let worktree_id = WorktreeId::from_proto(envelope.payload.worktree_id);
if let Some(worktree) = self.worktree_for_id(worktree_id, cx) {
worktree.update(cx, |worktree, cx| {
worktree
.as_remote()
.unwrap()
.disk_based_diagnostics_updating(cx);
});
}
Ok(())
}
fn handle_disk_based_diagnostics_updated(
&mut self,
envelope: TypedEnvelope<proto::DiskBasedDiagnosticsUpdated>,