diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-12-20 13:27:13 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-12-20 14:09:29 +0100 |
| commit | bc5a260f999aba1c92380abbd6f1e2af54bb293c (patch) | |
| tree | 5b5f652ef85b6c579a59d68283c771da96cfa4c4 | |
| parent | 3f786bb7d7648810d6fe7f76eabe0fa8186f1dcb (diff) | |
| download | rust-bc5a260f999aba1c92380abbd6f1e2af54bb293c.tar.gz rust-bc5a260f999aba1c92380abbd6f1e2af54bb293c.zip | |
Arc the package ids coming from flycheck
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics.rs | 16 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs | 17 |
2 files changed, 21 insertions, 12 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics.rs index 03294e5ab31..e64a15ae041 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics.rs +++ b/src/tools/rust-analyzer/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<usize, FxHashMap<Option<PackageId>, IntMap<FileId, Vec<Fix>>>>>; + Arc<IntMap<usize, FxHashMap<Option<Arc<PackageId>>, IntMap<FileId, Vec<Fix>>>>>; #[derive(Debug, Default, Clone)] pub struct DiagnosticsMapConfig { @@ -33,8 +33,10 @@ pub(crate) struct DiagnosticCollection { pub(crate) native_syntax: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>, pub(crate) native_semantic: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>, // FIXME: should be Vec<flycheck::Diagnostic> - pub(crate) check: - IntMap<usize, FxHashMap<Option<PackageId>, IntMap<FileId, Vec<lsp_types::Diagnostic>>>>, + pub(crate) check: IntMap< + usize, + FxHashMap<Option<Arc<PackageId>>, IntMap<FileId, Vec<lsp_types::Diagnostic>>>, + >, pub(crate) check_fixes: CheckFixes, changes: IntSet<FileId>, /// 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<PackageId>, + ) { 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<PackageId>, + package_id: &Option<Arc<PackageId>>, file_id: FileId, diagnostic: lsp_types::Diagnostic, fix: Option<Box<Fix>>, diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs index d178b8b1fdf..7ff36deb98b 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs +++ b/src/tools/rust-analyzer/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<AbsPathBuf>, diagnostic: Diagnostic, - package_id: Option<PackageId>, + package_id: Option<Arc<PackageId>>, }, /// Request clearing all outdated diagnostics. ClearDiagnostics { id: usize, /// The package whose diagnostics to clear, or if unspecified, all diagnostics. - package_id: Option<PackageId>, + package_id: Option<Arc<PackageId>>, }, /// Request check progress notification to client @@ -229,7 +230,7 @@ struct FlycheckActor { command_handle: Option<CommandHandle<CargoCheckMessage>>, /// The receiver side of the channel mentioned above. command_receiver: Option<Receiver<CargoCheckMessage>>, - package_status: FxHashMap<PackageId, DiagnosticReceived>, + package_status: FxHashMap<Arc<PackageId>, 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<PackageId> }, + Diagnostic { diagnostic: Diagnostic, package_id: Option<Arc<PackageId>> }, } 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, |
