diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs index 1cac954c393..c67ec39d48c 100644 --- a/crates/ra_cargo_watch/src/lib.rs +++ b/crates/ra_cargo_watch/src/lib.rs @@ -36,7 +36,7 @@ pub struct CheckOptions { #[derive(Debug)] pub struct CheckWatcher { // XXX: drop order is significant - cmd_send: Option>, + cmd_send: Sender, handle: Option>, pub task_recv: Receiver, } @@ -51,19 +51,12 @@ pub fn new(options: &CheckOptions, workspace_root: PathBuf) -> CheckWatcher { let mut check = CheckWatcherThread::new(options, workspace_root); check.run(&task_send, &cmd_recv); }); - CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle) } - } - - /// Returns a CheckWatcher that doesn't actually do anything - pub fn dummy() -> CheckWatcher { - CheckWatcher { task_recv: never(), cmd_send: None, handle: None } + CheckWatcher { task_recv, cmd_send, handle: Some(handle) } } /// Schedule a re-start of the cargo check worker. pub fn update(&self) { - if let Some(cmd_send) = &self.cmd_send { - cmd_send.send(CheckCommand::Update).unwrap(); - } + self.cmd_send.send(CheckCommand::Update).unwrap(); } } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index d35963e9568..c899ff6774b 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -14,7 +14,7 @@ time::{Duration, Instant}, }; -use crossbeam_channel::{select, unbounded, RecvError, Sender}; +use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; use lsp_types::{ ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, @@ -232,7 +232,7 @@ pub fn main_loop( Err(RecvError) => return Err("vfs died".into()), }, recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), - recv(world_state.check_watcher.task_recv) -> task => match task { + recv(world_state.check_watcher.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { Ok(task) => Event::CheckWatcher(task), Err(RecvError) => return Err("check watcher died".into()), } @@ -443,7 +443,9 @@ fn loop_turn( && loop_state.in_flight_libraries == 0 { loop_state.workspace_loaded = true; - world_state.check_watcher.update(); + if let Some(check_watcher) = &world_state.check_watcher { + check_watcher.update(); + } pool.execute({ let subs = loop_state.subscriptions.subscriptions(); let snap = world_state.snapshot(); @@ -615,7 +617,9 @@ fn on_notification( }; let not = match notification_cast::(not) { Ok(_params) => { - state.check_watcher.update(); + if let Some(check_watcher) = &state.check_watcher { + check_watcher.update(); + } return Ok(()); } Err(not) => not, diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 5680397ed82..ca045f93c84 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -57,7 +57,7 @@ pub struct WorldState { pub vfs: Arc>, pub task_receiver: Receiver, pub latest_requests: Arc>, - pub check_watcher: CheckWatcher, + pub check_watcher: Option, pub diagnostics: DiagnosticCollection, } @@ -176,11 +176,11 @@ pub fn new( }) .map(|cargo| { let cargo_project_root = cargo.workspace_root().to_path_buf(); - CheckWatcher::new(&options.cargo_watch, cargo_project_root) + Some(CheckWatcher::new(&options.cargo_watch, cargo_project_root)) }) .unwrap_or_else(|| { log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); - CheckWatcher::dummy() + None }); let mut analysis_host = AnalysisHost::new(lru_capacity);