Arc the package ids coming from flycheck

This commit is contained in:
Lukas Wirth 2024-12-20 13:27:13 +01:00
parent 7da17fe195
commit 4a8eb8c229
2 changed files with 21 additions and 12 deletions

View file

@ -15,7 +15,7 @@ use triomphe::Arc;
use crate::{global_state::GlobalStateSnapshot, lsp, lsp_ext, main_loop::DiagnosticsTaskKind}; use crate::{global_state::GlobalStateSnapshot, lsp, lsp_ext, main_loop::DiagnosticsTaskKind};
pub(crate) type CheckFixes = 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)] #[derive(Debug, Default, Clone)]
pub struct DiagnosticsMapConfig { 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_syntax: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>,
pub(crate) native_semantic: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>, pub(crate) native_semantic: IntMap<FileId, (DiagnosticsGeneration, Vec<lsp_types::Diagnostic>)>,
// FIXME: should be Vec<flycheck::Diagnostic> // FIXME: should be Vec<flycheck::Diagnostic>
pub(crate) check: pub(crate) check: IntMap<
IntMap<usize, FxHashMap<Option<PackageId>, IntMap<FileId, Vec<lsp_types::Diagnostic>>>>, usize,
FxHashMap<Option<Arc<PackageId>>, IntMap<FileId, Vec<lsp_types::Diagnostic>>>,
>,
pub(crate) check_fixes: CheckFixes, pub(crate) check_fixes: CheckFixes,
changes: IntSet<FileId>, changes: IntSet<FileId>,
/// Counter for supplying a new generation number for diagnostics. /// Counter for supplying a new generation number for diagnostics.
@ -74,7 +76,11 @@ impl DiagnosticCollection {
self.changes.insert(file_id); 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 { let Some(check) = self.check.get_mut(&flycheck_id) else {
return; return;
}; };
@ -84,7 +90,7 @@ impl DiagnosticCollection {
pub(crate) fn add_check_diagnostic( pub(crate) fn add_check_diagnostic(
&mut self, &mut self,
flycheck_id: usize, flycheck_id: usize,
package_id: &Option<PackageId>, package_id: &Option<Arc<PackageId>>,
file_id: FileId, file_id: FileId,
diagnostic: lsp_types::Diagnostic, diagnostic: lsp_types::Diagnostic,
fix: Option<Box<Fix>>, fix: Option<Box<Fix>>,

View file

@ -1,7 +1,7 @@
//! Flycheck provides the functionality needed to run `cargo check` to provide //! Flycheck provides the functionality needed to run `cargo check` to provide
//! LSP diagnostics based on the output of the command. //! 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 cargo_metadata::PackageId;
use crossbeam_channel::{select_biased, unbounded, Receiver, Sender}; use crossbeam_channel::{select_biased, unbounded, Receiver, Sender};
@ -13,6 +13,7 @@ pub(crate) use cargo_metadata::diagnostic::{
Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan, Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan,
}; };
use toolchain::Tool; use toolchain::Tool;
use triomphe::Arc;
use crate::command::{CommandHandle, ParseFromLine}; use crate::command::{CommandHandle, ParseFromLine};
@ -155,14 +156,14 @@ pub(crate) enum FlycheckMessage {
id: usize, id: usize,
workspace_root: Arc<AbsPathBuf>, workspace_root: Arc<AbsPathBuf>,
diagnostic: Diagnostic, diagnostic: Diagnostic,
package_id: Option<PackageId>, package_id: Option<Arc<PackageId>>,
}, },
/// Request clearing all outdated diagnostics. /// Request clearing all outdated diagnostics.
ClearDiagnostics { ClearDiagnostics {
id: usize, id: usize,
/// The package whose diagnostics to clear, or if unspecified, all diagnostics. /// 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 /// Request check progress notification to client
@ -229,7 +230,7 @@ struct FlycheckActor {
command_handle: Option<CommandHandle<CargoCheckMessage>>, command_handle: Option<CommandHandle<CargoCheckMessage>>,
/// The receiver side of the channel mentioned above. /// The receiver side of the channel mentioned above.
command_receiver: Option<Receiver<CargoCheckMessage>>, command_receiver: Option<Receiver<CargoCheckMessage>>,
package_status: FxHashMap<PackageId, DiagnosticReceived>, package_status: FxHashMap<Arc<PackageId>, DiagnosticReceived>,
} }
#[derive(PartialEq, Eq, Copy, Clone, Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
@ -370,7 +371,9 @@ impl FlycheckActor {
"artifact received" "artifact received"
); );
self.report_progress(Progress::DidCheckCrate(msg.target.name)); 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 } => { CargoCheckMessage::Diagnostic { diagnostic, package_id } => {
tracing::trace!( tracing::trace!(
@ -517,7 +520,7 @@ impl FlycheckActor {
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
enum CargoCheckMessage { enum CargoCheckMessage {
CompilerArtifact(cargo_metadata::Artifact), CompilerArtifact(cargo_metadata::Artifact),
Diagnostic { diagnostic: Diagnostic, package_id: Option<PackageId> }, Diagnostic { diagnostic: Diagnostic, package_id: Option<Arc<PackageId>> },
} }
impl ParseFromLine for CargoCheckMessage { impl ParseFromLine for CargoCheckMessage {
@ -534,7 +537,7 @@ impl ParseFromLine for CargoCheckMessage {
cargo_metadata::Message::CompilerMessage(msg) => { cargo_metadata::Message::CompilerMessage(msg) => {
Some(CargoCheckMessage::Diagnostic { Some(CargoCheckMessage::Diagnostic {
diagnostic: msg.message, diagnostic: msg.message,
package_id: Some(msg.package_id), package_id: Some(Arc::new(msg.package_id)),
}) })
} }
_ => None, _ => None,