Skip to content

Commit 78a2678

Browse files
bors[bot]matklad
andauthored
Merge #3770
3770: Pull options outwards r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents df8752b + 4c92725 commit 78a2678

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

crates/ra_cargo_watch/src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct CheckOptions {
3636
#[derive(Debug)]
3737
pub struct CheckWatcher {
3838
// XXX: drop order is significant
39-
cmd_send: Option<Sender<CheckCommand>>,
39+
cmd_send: Sender<CheckCommand>,
4040
handle: Option<jod_thread::JoinHandle<()>>,
4141
pub task_recv: Receiver<CheckTask>,
4242
}
@@ -51,19 +51,12 @@ impl CheckWatcher {
5151
let mut check = CheckWatcherThread::new(options, workspace_root);
5252
check.run(&task_send, &cmd_recv);
5353
});
54-
CheckWatcher { task_recv, cmd_send: Some(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 }
54+
CheckWatcher { task_recv, cmd_send, handle: Some(handle) }
6055
}
6156

6257
/// Schedule a re-start of the cargo check worker.
6358
pub fn update(&self) {
64-
if let Some(cmd_send) = &self.cmd_send {
65-
cmd_send.send(CheckCommand::Update).unwrap();
66-
}
59+
self.cmd_send.send(CheckCommand::Update).unwrap();
6760
}
6861
}
6962

crates/rust-analyzer/src/main_loop.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
time::{Duration, Instant},
1515
};
1616

17-
use crossbeam_channel::{select, unbounded, RecvError, Sender};
17+
use crossbeam_channel::{never, select, unbounded, RecvError, Sender};
1818
use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
1919
use lsp_types::{
2020
ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin,
@@ -232,7 +232,7 @@ pub fn main_loop(
232232
Err(RecvError) => return Err("vfs died".into()),
233233
},
234234
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 {
236236
Ok(task) => Event::CheckWatcher(task),
237237
Err(RecvError) => return Err("check watcher died".into()),
238238
}
@@ -443,7 +443,9 @@ fn loop_turn(
443443
&& loop_state.in_flight_libraries == 0
444444
{
445445
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+
}
447449
pool.execute({
448450
let subs = loop_state.subscriptions.subscriptions();
449451
let snap = world_state.snapshot();
@@ -615,7 +617,9 @@ fn on_notification(
615617
};
616618
let not = match notification_cast::<req::DidSaveTextDocument>(not) {
617619
Ok(_params) => {
618-
state.check_watcher.update();
620+
if let Some(check_watcher) = &state.check_watcher {
621+
check_watcher.update();
622+
}
619623
return Ok(());
620624
}
621625
Err(not) => not,

crates/rust-analyzer/src/world.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct WorldState {
5757
pub vfs: Arc<RwLock<Vfs>>,
5858
pub task_receiver: Receiver<VfsTask>,
5959
pub latest_requests: Arc<RwLock<LatestRequests>>,
60-
pub check_watcher: CheckWatcher,
60+
pub check_watcher: Option<CheckWatcher>,
6161
pub diagnostics: DiagnosticCollection,
6262
}
6363

@@ -176,11 +176,11 @@ impl WorldState {
176176
})
177177
.map(|cargo| {
178178
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))
180180
})
181181
.unwrap_or_else(|| {
182182
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
183-
CheckWatcher::dummy()
183+
None
184184
});
185185

186186
let mut analysis_host = AnalysisHost::new(lru_capacity);

0 commit comments

Comments
 (0)