Pull options outwards

This commit is contained in:
Aleksey Kladov 2020-03-30 11:46:04 +02:00
parent 12297ab675
commit 4c9272583c
3 changed files with 14 additions and 17 deletions

View file

@ -36,7 +36,7 @@ pub struct CheckOptions {
#[derive(Debug)] #[derive(Debug)]
pub struct CheckWatcher { pub struct CheckWatcher {
// XXX: drop order is significant // XXX: drop order is significant
cmd_send: Option<Sender<CheckCommand>>, cmd_send: Sender<CheckCommand>,
handle: Option<jod_thread::JoinHandle<()>>, handle: Option<jod_thread::JoinHandle<()>>,
pub task_recv: Receiver<CheckTask>, pub task_recv: Receiver<CheckTask>,
} }
@ -51,19 +51,12 @@ impl CheckWatcher {
let mut check = CheckWatcherThread::new(options, workspace_root); let mut check = CheckWatcherThread::new(options, workspace_root);
check.run(&task_send, &cmd_recv); check.run(&task_send, &cmd_recv);
}); });
CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle) } CheckWatcher { task_recv, 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 }
} }
/// Schedule a re-start of the cargo check worker. /// Schedule a re-start of the cargo check worker.
pub fn update(&self) { pub fn update(&self) {
if let Some(cmd_send) = &self.cmd_send { self.cmd_send.send(CheckCommand::Update).unwrap();
cmd_send.send(CheckCommand::Update).unwrap();
}
} }
} }

View file

@ -14,7 +14,7 @@ use std::{
time::{Duration, Instant}, 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_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
use lsp_types::{ use lsp_types::{
ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin, ClientCapabilities, NumberOrString, WorkDoneProgress, WorkDoneProgressBegin,
@ -232,7 +232,7 @@ pub fn main_loop(
Err(RecvError) => return Err("vfs died".into()), Err(RecvError) => return Err("vfs died".into()),
}, },
recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), 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), Ok(task) => Event::CheckWatcher(task),
Err(RecvError) => return Err("check watcher died".into()), Err(RecvError) => return Err("check watcher died".into()),
} }
@ -443,7 +443,9 @@ fn loop_turn(
&& loop_state.in_flight_libraries == 0 && loop_state.in_flight_libraries == 0
{ {
loop_state.workspace_loaded = true; loop_state.workspace_loaded = true;
world_state.check_watcher.update(); if let Some(check_watcher) = &world_state.check_watcher {
check_watcher.update();
}
pool.execute({ pool.execute({
let subs = loop_state.subscriptions.subscriptions(); let subs = loop_state.subscriptions.subscriptions();
let snap = world_state.snapshot(); let snap = world_state.snapshot();
@ -615,7 +617,9 @@ fn on_notification(
}; };
let not = match notification_cast::<req::DidSaveTextDocument>(not) { let not = match notification_cast::<req::DidSaveTextDocument>(not) {
Ok(_params) => { Ok(_params) => {
state.check_watcher.update(); if let Some(check_watcher) = &state.check_watcher {
check_watcher.update();
}
return Ok(()); return Ok(());
} }
Err(not) => not, Err(not) => not,

View file

@ -57,7 +57,7 @@ pub struct WorldState {
pub vfs: Arc<RwLock<Vfs>>, pub vfs: Arc<RwLock<Vfs>>,
pub task_receiver: Receiver<VfsTask>, pub task_receiver: Receiver<VfsTask>,
pub latest_requests: Arc<RwLock<LatestRequests>>, pub latest_requests: Arc<RwLock<LatestRequests>>,
pub check_watcher: CheckWatcher, pub check_watcher: Option<CheckWatcher>,
pub diagnostics: DiagnosticCollection, pub diagnostics: DiagnosticCollection,
} }
@ -176,11 +176,11 @@ impl WorldState {
}) })
.map(|cargo| { .map(|cargo| {
let cargo_project_root = cargo.workspace_root().to_path_buf(); 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(|| { .unwrap_or_else(|| {
log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
CheckWatcher::dummy() None
}); });
let mut analysis_host = AnalysisHost::new(lru_capacity); let mut analysis_host = AnalysisHost::new(lru_capacity);