aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_cargo_watch/src/lib.rs13
-rw-r--r--crates/rust-analyzer/src/main_loop.rs12
-rw-r--r--crates/rust-analyzer/src/world.rs6
3 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs
index 1cac954c3..c67ec39d4 100644
--- a/crates/ra_cargo_watch/src/lib.rs
+++ b/crates/ra_cargo_watch/src/lib.rs
@@ -36,7 +36,7 @@ pub struct CheckOptions {
36#[derive(Debug)] 36#[derive(Debug)]
37pub struct CheckWatcher { 37pub struct CheckWatcher {
38 // XXX: drop order is significant 38 // XXX: drop order is significant
39 cmd_send: Option<Sender<CheckCommand>>, 39 cmd_send: Sender<CheckCommand>,
40 handle: Option<jod_thread::JoinHandle<()>>, 40 handle: Option<jod_thread::JoinHandle<()>>,
41 pub task_recv: Receiver<CheckTask>, 41 pub task_recv: Receiver<CheckTask>,
42} 42}
@@ -51,19 +51,12 @@ impl CheckWatcher {
51 let mut check = CheckWatcherThread::new(options, workspace_root); 51 let mut check = CheckWatcherThread::new(options, workspace_root);
52 check.run(&task_send, &cmd_recv); 52 check.run(&task_send, &cmd_recv);
53 }); 53 });
54 CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle) } 54 CheckWatcher { task_recv, cmd_send, handle: Some(handle) }
55 }
56
57 /// Returns a CheckWatcher that doesn't actually do anything
58 pub fn dummy() -> CheckWatcher {
59 CheckWatcher { task_recv: never(), cmd_send: None, handle: None }
60 } 55 }
61 56
62 /// Schedule a re-start of the cargo check worker. 57 /// Schedule a re-start of the cargo check worker.
63 pub fn update(&self) { 58 pub fn update(&self) {
64 if let Some(cmd_send) = &self.cmd_send { 59 self.cmd_send.send(CheckCommand::Update).unwrap();
65 cmd_send.send(CheckCommand::Update).unwrap();
66 }
67 } 60 }
68} 61}
69 62
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index d35963e95..c899ff677 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -14,7 +14,7 @@ use std::{
14 time::{Duration, Instant}, 14 time::{Duration, Instant},
15}; 15};
16 16
17use crossbeam_channel::{select, unbounded, RecvError, Sender}; 17use crossbeam_channel::{never, select, unbounded, RecvError, Sender};
18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; 18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
19use lsp_types::{ 19use lsp_types::{
20 ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, 20 ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin,
@@ -232,7 +232,7 @@ pub fn main_loop(
232 Err(RecvError) => return Err("vfs died".into()), 232 Err(RecvError) => return Err("vfs died".into()),
233 }, 233 },
234 recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), 234 recv(libdata_receiver) -> data => Event::Lib(data.unwrap()),
235 recv(world_state.check_watcher.task_recv) -> task => match task { 235 recv(world_state.check_watcher.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task {
236 Ok(task) => Event::CheckWatcher(task), 236 Ok(task) => Event::CheckWatcher(task),
237 Err(RecvError) => return Err("check watcher died".into()), 237 Err(RecvError) => return Err("check watcher died".into()),
238 } 238 }
@@ -443,7 +443,9 @@ fn loop_turn(
443 && loop_state.in_flight_libraries == 0 443 && loop_state.in_flight_libraries == 0
444 { 444 {
445 loop_state.workspace_loaded = true; 445 loop_state.workspace_loaded = true;
446 world_state.check_watcher.update(); 446 if let Some(check_watcher) = &world_state.check_watcher {
447 check_watcher.update();
448 }
447 pool.execute({ 449 pool.execute({
448 let subs = loop_state.subscriptions.subscriptions(); 450 let subs = loop_state.subscriptions.subscriptions();
449 let snap = world_state.snapshot(); 451 let snap = world_state.snapshot();
@@ -615,7 +617,9 @@ fn on_notification(
615 }; 617 };
616 let not = match notification_cast::<req::DidSaveTextDocument>(not) { 618 let not = match notification_cast::<req::DidSaveTextDocument>(not) {
617 Ok(_params) => { 619 Ok(_params) => {
618 state.check_watcher.update(); 620 if let Some(check_watcher) = &state.check_watcher {
621 check_watcher.update();
622 }
619 return Ok(()); 623 return Ok(());
620 } 624 }
621 Err(not) => not, 625 Err(not) => not,
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index 5680397ed..ca045f93c 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -57,7 +57,7 @@ pub struct WorldState {
57 pub vfs: Arc<RwLock<Vfs>>, 57 pub vfs: Arc<RwLock<Vfs>>,
58 pub task_receiver: Receiver<VfsTask>, 58 pub task_receiver: Receiver<VfsTask>,
59 pub latest_requests: Arc<RwLock<LatestRequests>>, 59 pub latest_requests: Arc<RwLock<LatestRequests>>,
60 pub check_watcher: CheckWatcher, 60 pub check_watcher: Option<CheckWatcher>,
61 pub diagnostics: DiagnosticCollection, 61 pub diagnostics: DiagnosticCollection,
62} 62}
63 63
@@ -176,11 +176,11 @@ impl WorldState {
176 }) 176 })
177 .map(|cargo| { 177 .map(|cargo| {
178 let cargo_project_root = cargo.workspace_root().to_path_buf(); 178 let cargo_project_root = cargo.workspace_root().to_path_buf();
179 CheckWatcher::new(&options.cargo_watch, cargo_project_root) 179 Some(CheckWatcher::new(&options.cargo_watch, cargo_project_root))
180 }) 180 })
181 .unwrap_or_else(|| { 181 .unwrap_or_else(|| {
182 log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); 182 log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
183 CheckWatcher::dummy() 183 None
184 }); 184 });
185 185
186 let mut analysis_host = AnalysisHost::new(lru_capacity); 186 let mut analysis_host = AnalysisHost::new(lru_capacity);