Skip to content

Commit bc5a260

Browse files
committed
Arc the package ids coming from flycheck
1 parent 3f786bb commit bc5a260

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use triomphe::Arc;
1515
use crate::{global_state::GlobalStateSnapshot, lsp, lsp_ext, main_loop::DiagnosticsTaskKind};
1616

1717
pub(crate) type CheckFixes =
18-
Arc<IntMap<usize, FxHashMap<Option<PackageId>, IntMap<FileId, Vec<Fix>>>>>;
18+
Arc<IntMap<usize, FxHashMap<Option<Arc<PackageId>>, IntMap<FileId, Vec<Fix>>>>>;
1919

2020
#[derive(Debug, Default, Clone)]
2121
pub struct DiagnosticsMapConfig {
@@ -33,8 +33,10 @@ pub(crate) struct DiagnosticCollection {
3333
pub(crate) native_syntax: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>,
3434
pub(crate) native_semantic: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>,
3535
// FIXME: should be Vec<flycheck::Diagnostic>
36-
pub(crate) check:
37-
IntMap<usize, FxHashMap<Option<PackageId>, IntMap<FileId, Vec<lsp_types::Diagnostic>>>>,
36+
pub(crate) check: IntMap<
37+
usize,
38+
FxHashMap<Option<Arc<PackageId>>, IntMap<FileId, Vec<lsp_types::Diagnostic>>>,
39+
>,
3840
pub(crate) check_fixes: CheckFixes,
3941
changes: IntSet<FileId>,
4042
/// Counter for supplying a new generation number for diagnostics.
@@ -74,7 +76,11 @@ impl DiagnosticCollection {
7476
self.changes.insert(file_id);
7577
}
7678

77-
pub(crate) fn clear_check_for_package(&mut self, flycheck_id: usize, package_id: PackageId) {
79+
pub(crate) fn clear_check_for_package(
80+
&mut self,
81+
flycheck_id: usize,
82+
package_id: Arc<PackageId>,
83+
) {
7884
let Some(check) = self.check.get_mut(&flycheck_id) else {
7985
return;
8086
};
@@ -84,7 +90,7 @@ impl DiagnosticCollection {
8490
pub(crate) fn add_check_diagnostic(
8591
&mut self,
8692
flycheck_id: usize,
87-
package_id: &Option<PackageId>,
93+
package_id: &Option<Arc<PackageId>>,
8894
file_id: FileId,
8995
diagnostic: lsp_types::Diagnostic,
9096
fix: Option<Box<Fix>>,

src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Flycheck provides the functionality needed to run `cargo check` to provide
22
//! LSP diagnostics based on the output of the command.
33
4-
use std::{fmt, io, mem, process::Command, sync::Arc, time::Duration};
4+
use std::{fmt, io, mem, process::Command, time::Duration};
55

66
use cargo_metadata::PackageId;
77
use crossbeam_channel::{select_biased, unbounded, Receiver, Sender};
@@ -13,6 +13,7 @@ pub(crate) use cargo_metadata::diagnostic::{
1313
Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan,
1414
};
1515
use toolchain::Tool;
16+
use triomphe::Arc;
1617

1718
use crate::command::{CommandHandle, ParseFromLine};
1819

@@ -155,14 +156,14 @@ pub(crate) enum FlycheckMessage {
155156
id: usize,
156157
workspace_root: Arc<AbsPathBuf>,
157158
diagnostic: Diagnostic,
158-
package_id: Option<PackageId>,
159+
package_id: Option<Arc<PackageId>>,
159160
},
160161

161162
/// Request clearing all outdated diagnostics.
162163
ClearDiagnostics {
163164
id: usize,
164165
/// The package whose diagnostics to clear, or if unspecified, all diagnostics.
165-
package_id: Option<PackageId>,
166+
package_id: Option<Arc<PackageId>>,
166167
},
167168

168169
/// Request check progress notification to client
@@ -229,7 +230,7 @@ struct FlycheckActor {
229230
command_handle: Option<CommandHandle<CargoCheckMessage>>,
230231
/// The receiver side of the channel mentioned above.
231232
command_receiver: Option<Receiver<CargoCheckMessage>>,
232-
package_status: FxHashMap<PackageId, DiagnosticReceived>,
233+
package_status: FxHashMap<Arc<PackageId>, DiagnosticReceived>,
233234
}
234235

235236
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
@@ -370,7 +371,9 @@ impl FlycheckActor {
370371
"artifact received"
371372
);
372373
self.report_progress(Progress::DidCheckCrate(msg.target.name));
373-
self.package_status.entry(msg.package_id).or_insert(DiagnosticReceived::No);
374+
self.package_status
375+
.entry(Arc::new(msg.package_id))
376+
.or_insert(DiagnosticReceived::No);
374377
}
375378
CargoCheckMessage::Diagnostic { diagnostic, package_id } => {
376379
tracing::trace!(
@@ -517,7 +520,7 @@ impl FlycheckActor {
517520
#[allow(clippy::large_enum_variant)]
518521
enum CargoCheckMessage {
519522
CompilerArtifact(cargo_metadata::Artifact),
520-
Diagnostic { diagnostic: Diagnostic, package_id: Option<PackageId> },
523+
Diagnostic { diagnostic: Diagnostic, package_id: Option<Arc<PackageId>> },
521524
}
522525

523526
impl ParseFromLine for CargoCheckMessage {
@@ -534,7 +537,7 @@ impl ParseFromLine for CargoCheckMessage {
534537
cargo_metadata::Message::CompilerMessage(msg) => {
535538
Some(CargoCheckMessage::Diagnostic {
536539
diagnostic: msg.message,
537-
package_id: Some(msg.package_id),
540+
package_id: Some(Arc::new(msg.package_id)),
538541
})
539542
}
540543
_ => None,

0 commit comments

Comments
 (0)