Unnamed repository; edit this file 'description' to name the repository.
Arc the package ids coming from flycheck
Lukas Wirth 2024-12-20
parent 7da17fe · commit 4a8eb8c
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs16
-rw-r--r--crates/rust-analyzer/src/flycheck.rs17
2 files changed, 21 insertions, 12 deletions
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<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/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<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,