diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index d77844a363..b0c3c6a061 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -31,6 +31,23 @@ use crate::{ use ra_db::ExternSourceId; use rustc_hash::{FxHashMap, FxHashSet}; +fn create_watcher(workspaces: &[ProjectWorkspace], options: &Options) -> CheckWatcher { + workspaces + .iter() + .find_map(|w| match w { + ProjectWorkspace::Cargo { cargo, .. } => Some(cargo), + ProjectWorkspace::Json { .. } => None, + }) + .map(|cargo| { + let cargo_project_root = cargo.workspace_root().to_path_buf(); + Some(CheckWatcher::new(&options.cargo_watch, cargo_project_root)) + }) + .unwrap_or_else(|| { + log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); + None + }) +} + #[derive(Debug, Clone)] pub struct Options { pub publish_decorations: bool, @@ -168,20 +185,7 @@ impl WorldState { change.set_crate_graph(crate_graph); // FIXME: Figure out the multi-workspace situation - let check_watcher = workspaces - .iter() - .find_map(|w| match w { - ProjectWorkspace::Cargo { cargo, .. } => Some(cargo), - ProjectWorkspace::Json { .. } => None, - }) - .map(|cargo| { - let cargo_project_root = cargo.workspace_root().to_path_buf(); - Some(CheckWatcher::new(&options.cargo_watch, cargo_project_root)) - }) - .unwrap_or_else(|| { - log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); - None - }); + let check_watcher = create_watcher(&workspaces, &options); let mut analysis_host = AnalysisHost::new(lru_capacity); analysis_host.apply_change(change); @@ -207,6 +211,7 @@ impl WorldState { ) { self.feature_flags = Arc::new(feature_flags); self.analysis_host.update_lru_capacity(lru_capacity); + self.check_watcher = create_watcher(&self.workspaces, &options); self.options = options; }