Unnamed repository; edit this file 'description' to name the repository.
fix: Fix flycheck generations not being synced for multiple workspaces
The diagnostics collection globally tracks the generation for all loaded workspaces as its shared between them, yet the flycheck actors track their own separate generations per workspace. This mismatch could cause flycheck to not work correctly when multiple workspaces were loaded.
Lukas Wirth 4 months ago
parent 624761a · commit d639142
-rw-r--r--crates/rust-analyzer/src/flycheck.rs8
-rw-r--r--crates/rust-analyzer/src/reload.rs7
2 files changed, 8 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/flycheck.rs b/crates/rust-analyzer/src/flycheck.rs
index 14a4a1752f..b062641691 100644
--- a/crates/rust-analyzer/src/flycheck.rs
+++ b/crates/rust-analyzer/src/flycheck.rs
@@ -147,13 +147,13 @@ pub(crate) struct FlycheckHandle {
sender: Sender<StateChange>,
_thread: stdx::thread::JoinHandle,
id: usize,
- generation: AtomicUsize,
+ generation: Arc<AtomicUsize>,
}
impl FlycheckHandle {
pub(crate) fn spawn(
id: usize,
- generation: DiagnosticsGeneration,
+ generation: Arc<AtomicUsize>,
sender: Sender<FlycheckMessage>,
config: FlycheckConfig,
sysroot_root: Option<AbsPathBuf>,
@@ -163,7 +163,7 @@ impl FlycheckHandle {
) -> FlycheckHandle {
let actor = FlycheckActor::new(
id,
- generation,
+ generation.load(Ordering::Relaxed),
sender,
config,
sysroot_root,
@@ -176,7 +176,7 @@ impl FlycheckHandle {
stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker, format!("Flycheck{id}"))
.spawn(move || actor.run(receiver))
.expect("failed to spawn thread");
- FlycheckHandle { id, generation: generation.into(), sender, _thread: thread }
+ FlycheckHandle { id, generation, sender, _thread: thread }
}
/// Schedule a re-start of the cargo check worker to do a workspace wide check.
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 317c112365..e3a5ee2219 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -13,7 +13,7 @@
//! project is currently loading and we don't have a full project model, we
//! still want to respond to various requests.
// FIXME: This is a mess that needs some untangling work
-use std::{iter, mem};
+use std::{iter, mem, sync::atomic::AtomicUsize};
use hir::{ChangeWithProcMacros, ProcMacrosBuilder, db::DefDatabase};
use ide_db::{
@@ -866,12 +866,13 @@ impl GlobalState {
let invocation_strategy = config.invocation_strategy();
let next_gen =
self.flycheck.iter().map(FlycheckHandle::generation).max().unwrap_or_default() + 1;
+ let generation = Arc::new(AtomicUsize::new(next_gen));
self.flycheck = match invocation_strategy {
crate::flycheck::InvocationStrategy::Once => {
vec![FlycheckHandle::spawn(
0,
- next_gen,
+ generation.clone(),
sender.clone(),
config,
None,
@@ -915,7 +916,7 @@ impl GlobalState {
.map(|(id, (root, manifest_path, target_dir), sysroot_root)| {
FlycheckHandle::spawn(
id,
- next_gen,
+ generation.clone(),
sender.clone(),
config.clone(),
sysroot_root,