diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 5c0fcc38bb..3971fabf64 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -14,7 +14,7 @@ use gpui::{ }; use language::{Bias, Buffer, Diagnostic, DiagnosticEntry, Point, Selection, SelectionGoal}; use postage::watch; -use project::{Project, ProjectPath, WorktreeId}; +use project::{Project, ProjectPath}; use std::{cmp::Ordering, mem, ops::Range, path::PathBuf, rc::Rc, sync::Arc}; use util::TryFutureExt; use workspace::{NavHistory, Workspace}; @@ -49,7 +49,7 @@ struct ProjectDiagnosticsEditor { editor: ViewHandle, excerpts: ModelHandle, path_states: Vec, - paths_to_update: HashMap>, + paths_to_update: BTreeSet, build_settings: BuildSettings, settings: watch::Receiver, } @@ -119,16 +119,12 @@ impl ProjectDiagnosticsEditor { ) -> Self { let project = model.read(cx).project.clone(); cx.subscribe(&project, |this, _, event, cx| match event { - project::Event::DiskBasedDiagnosticsUpdated { worktree_id } => { - if let Some(paths) = this.paths_to_update.remove(&worktree_id) { - this.update_excerpts(paths, cx); - } + project::Event::DiskBasedDiagnosticsFinished => { + let paths = mem::take(&mut this.paths_to_update); + this.update_excerpts(paths, cx); } project::Event::DiagnosticsUpdated(path) => { - this.paths_to_update - .entry(path.worktree_id) - .or_default() - .insert(path.clone()); + this.paths_to_update.insert(path.clone()); } _ => {} }) @@ -909,7 +905,7 @@ mod tests { worktree_id, path: Arc::from("/test/consts.rs".as_ref()), })); - cx.emit(project::Event::DiskBasedDiagnosticsUpdated { worktree_id }); + cx.emit(project::Event::DiskBasedDiagnosticsFinished); }); view.next_notification(&cx).await; @@ -1029,7 +1025,7 @@ mod tests { worktree_id, path: Arc::from("/test/consts.rs".as_ref()), })); - cx.emit(project::Event::DiskBasedDiagnosticsUpdated { worktree_id }); + cx.emit(project::Event::DiskBasedDiagnosticsFinished); }); view.next_notification(&cx).await; diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rs index 072738fa77..3390f74a84 100644 --- a/crates/diagnostics/src/items.rs +++ b/crates/diagnostics/src/items.rs @@ -19,7 +19,7 @@ impl DiagnosticSummary { cx: &mut ViewContext, ) -> Self { cx.subscribe(project, |this, project, event, cx| match event { - project::Event::DiskBasedDiagnosticsUpdated { .. } => { + project::Event::DiskBasedDiagnosticsUpdated => { this.summary = project.read(cx).diagnostic_summary(cx); cx.notify(); } diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 4b16494d9d..5eec2f9b9e 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -64,7 +64,7 @@ pub enum Event { ActiveEntryChanged(Option), WorktreeRemoved(WorktreeId), DiskBasedDiagnosticsStarted, - DiskBasedDiagnosticsUpdated { worktree_id: WorktreeId }, + DiskBasedDiagnosticsUpdated, DiskBasedDiagnosticsFinished, DiagnosticsUpdated(ProjectPath), } @@ -527,14 +527,10 @@ impl Project { .entry((worktree_id, language.name().to_string())) { hash_map::Entry::Occupied(e) => Some(e.get().clone()), - hash_map::Entry::Vacant(e) => Self::start_language_server( - self.client.clone(), - language, - worktree_id, - &worktree_abs_path, - cx, - ) - .map(|server| e.insert(server).clone()), + hash_map::Entry::Vacant(e) => { + Self::start_language_server(self.client.clone(), language, &worktree_abs_path, cx) + .map(|server| e.insert(server).clone()) + } }; buffer.update(cx, |buffer, cx| { @@ -547,7 +543,6 @@ impl Project { fn start_language_server( rpc: Arc, language: Arc, - worktree_id: WorktreeId, worktree_path: &Path, cx: &mut ModelContext, ) -> Option> { @@ -626,12 +621,9 @@ impl Project { match message { LspEvent::DiagnosticsStart => { let send = this.update(&mut cx, |this, cx| { - this.disk_based_diagnostics_started(worktree_id, cx); + this.disk_based_diagnostics_started(cx); this.remote_id().map(|project_id| { - rpc.send(proto::DiskBasedDiagnosticsUpdating { - project_id, - worktree_id: worktree_id.to_proto(), - }) + rpc.send(proto::DiskBasedDiagnosticsUpdating { project_id }) }) }); if let Some(send) = send { @@ -646,12 +638,9 @@ impl Project { } LspEvent::DiagnosticsFinish => { let send = this.update(&mut cx, |this, cx| { - this.disk_based_diagnostics_finished(worktree_id, cx); + this.disk_based_diagnostics_finished(cx); this.remote_id().map(|project_id| { - rpc.send(proto::DiskBasedDiagnosticsUpdated { - project_id, - worktree_id: worktree_id.to_proto(), - }) + rpc.send(proto::DiskBasedDiagnosticsUpdated { project_id }) }) }); if let Some(send) = send { @@ -831,19 +820,15 @@ impl Project { }) } - fn disk_based_diagnostics_started(&mut self, _: WorktreeId, cx: &mut ModelContext) { + fn disk_based_diagnostics_started(&mut self, cx: &mut ModelContext) { self.language_servers_with_diagnostics_running += 1; if self.language_servers_with_diagnostics_running == 1 { cx.emit(Event::DiskBasedDiagnosticsStarted); } } - fn disk_based_diagnostics_finished( - &mut self, - worktree_id: WorktreeId, - cx: &mut ModelContext, - ) { - cx.emit(Event::DiskBasedDiagnosticsUpdated { worktree_id }); + fn disk_based_diagnostics_finished(&mut self, cx: &mut ModelContext) { + cx.emit(Event::DiskBasedDiagnosticsUpdated); self.language_servers_with_diagnostics_running -= 1; if self.language_servers_with_diagnostics_running == 0 { cx.emit(Event::DiskBasedDiagnosticsFinished); @@ -1010,27 +995,21 @@ impl Project { fn handle_disk_based_diagnostics_updating( &mut self, - envelope: TypedEnvelope, + _: TypedEnvelope, _: Arc, cx: &mut ModelContext, ) -> Result<()> { - self.disk_based_diagnostics_started( - WorktreeId::from_proto(envelope.payload.worktree_id), - cx, - ); + self.disk_based_diagnostics_started(cx); Ok(()) } fn handle_disk_based_diagnostics_updated( &mut self, - envelope: TypedEnvelope, + _: TypedEnvelope, _: Arc, cx: &mut ModelContext, ) -> Result<()> { - self.disk_based_diagnostics_finished( - WorktreeId::from_proto(envelope.payload.worktree_id), - cx, - ); + self.disk_based_diagnostics_finished(cx); Ok(()) } @@ -1491,7 +1470,11 @@ mod tests { fake_server.end_progress(&progress_token).await; assert_eq!( events.next().await.unwrap(), - Event::DiskBasedDiagnosticsUpdated { worktree_id } + Event::DiskBasedDiagnosticsUpdated + ); + assert_eq!( + events.next().await.unwrap(), + Event::DiskBasedDiagnosticsFinished ); let (buffer, _) = tree diff --git a/crates/rpc/proto/zed.proto b/crates/rpc/proto/zed.proto index 47774bf360..973d459310 100644 --- a/crates/rpc/proto/zed.proto +++ b/crates/rpc/proto/zed.proto @@ -191,12 +191,10 @@ message DiagnosticSummary { message DiskBasedDiagnosticsUpdating { uint64 project_id = 1; - uint64 worktree_id = 2; } message DiskBasedDiagnosticsUpdated { uint64 project_id = 1; - uint64 worktree_id = 2; } message GetChannels {}