diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs index 03294e5ab3..e64a15ae04 100644 --- a/crates/rust-analyzer/src/diagnostics.rs +++ b/crates/rust-analyzer/src/diagnostics.rs @@ -15,7 +15,7 @@ use triomphe::Arc; use crate::{global_state::GlobalStateSnapshot, lsp, lsp_ext, main_loop::DiagnosticsTaskKind}; pub(crate) type CheckFixes = - Arc, IntMap>>>>; + Arc>, IntMap>>>>; #[derive(Debug, Default, Clone)] pub struct DiagnosticsMapConfig { @@ -33,8 +33,10 @@ pub(crate) struct DiagnosticCollection { pub(crate) native_syntax: IntMap)>, pub(crate) native_semantic: IntMap)>, // FIXME: should be Vec - pub(crate) check: - IntMap, IntMap>>>, + pub(crate) check: IntMap< + usize, + FxHashMap>, IntMap>>, + >, pub(crate) check_fixes: CheckFixes, changes: IntSet, /// Counter for supplying a new generation number for diagnostics. @@ -74,7 +76,11 @@ impl DiagnosticCollection { self.changes.insert(file_id); } - pub(crate) fn clear_check_for_package(&mut self, flycheck_id: usize, package_id: PackageId) { + pub(crate) fn clear_check_for_package( + &mut self, + flycheck_id: usize, + package_id: Arc, + ) { let Some(check) = self.check.get_mut(&flycheck_id) else { return; }; @@ -84,7 +90,7 @@ impl DiagnosticCollection { pub(crate) fn add_check_diagnostic( &mut self, flycheck_id: usize, - package_id: &Option, + package_id: &Option>, file_id: FileId, diagnostic: lsp_types::Diagnostic, fix: Option>, diff --git a/crates/rust-analyzer/src/flycheck.rs b/crates/rust-analyzer/src/flycheck.rs index d178b8b1fd..7ff36deb98 100644 --- a/crates/rust-analyzer/src/flycheck.rs +++ b/crates/rust-analyzer/src/flycheck.rs @@ -1,7 +1,7 @@ //! Flycheck provides the functionality needed to run `cargo check` to provide //! LSP diagnostics based on the output of the command. -use std::{fmt, io, mem, process::Command, sync::Arc, time::Duration}; +use std::{fmt, io, mem, process::Command, time::Duration}; use cargo_metadata::PackageId; use crossbeam_channel::{select_biased, unbounded, Receiver, Sender}; @@ -13,6 +13,7 @@ pub(crate) use cargo_metadata::diagnostic::{ Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan, }; use toolchain::Tool; +use triomphe::Arc; use crate::command::{CommandHandle, ParseFromLine}; @@ -155,14 +156,14 @@ pub(crate) enum FlycheckMessage { id: usize, workspace_root: Arc, diagnostic: Diagnostic, - package_id: Option, + package_id: Option>, }, /// Request clearing all outdated diagnostics. ClearDiagnostics { id: usize, /// The package whose diagnostics to clear, or if unspecified, all diagnostics. - package_id: Option, + package_id: Option>, }, /// Request check progress notification to client @@ -229,7 +230,7 @@ struct FlycheckActor { command_handle: Option>, /// The receiver side of the channel mentioned above. command_receiver: Option>, - package_status: FxHashMap, + package_status: FxHashMap, DiagnosticReceived>, } #[derive(PartialEq, Eq, Copy, Clone, Debug)] @@ -370,7 +371,9 @@ impl FlycheckActor { "artifact received" ); self.report_progress(Progress::DidCheckCrate(msg.target.name)); - self.package_status.entry(msg.package_id).or_insert(DiagnosticReceived::No); + self.package_status + .entry(Arc::new(msg.package_id)) + .or_insert(DiagnosticReceived::No); } CargoCheckMessage::Diagnostic { diagnostic, package_id } => { tracing::trace!( @@ -517,7 +520,7 @@ impl FlycheckActor { #[allow(clippy::large_enum_variant)] enum CargoCheckMessage { CompilerArtifact(cargo_metadata::Artifact), - Diagnostic { diagnostic: Diagnostic, package_id: Option }, + Diagnostic { diagnostic: Diagnostic, package_id: Option> }, } impl ParseFromLine for CargoCheckMessage { @@ -534,7 +537,7 @@ impl ParseFromLine for CargoCheckMessage { cargo_metadata::Message::CompilerMessage(msg) => { Some(CargoCheckMessage::Diagnostic { diagnostic: msg.message, - package_id: Some(msg.package_id), + package_id: Some(Arc::new(msg.package_id)), }) } _ => None,