diff --git a/crates/rust-analyzer/src/flycheck.rs b/crates/rust-analyzer/src/flycheck.rs index 14a4a1752f41..b06264169188 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, _thread: stdx::thread::JoinHandle, id: usize, - generation: AtomicUsize, + generation: Arc, } impl FlycheckHandle { pub(crate) fn spawn( id: usize, - generation: DiagnosticsGeneration, + generation: Arc, sender: Sender, config: FlycheckConfig, sysroot_root: Option, @@ -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 317c1123659e..e3a5ee221973 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,