Merge #3770
3770: Pull options outwards r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
78a2678b6d
@ -36,7 +36,7 @@ pub struct CheckOptions {
|
||||
#[derive(Debug)]
|
||||
pub struct CheckWatcher {
|
||||
// XXX: drop order is significant
|
||||
cmd_send: Option<Sender<CheckCommand>>,
|
||||
cmd_send: Sender<CheckCommand>,
|
||||
handle: Option<jod_thread::JoinHandle<()>>,
|
||||
pub task_recv: Receiver<CheckTask>,
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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::<req::DidSaveTextDocument>(not) {
|
||||
Ok(_params) => {
|
||||
state.check_watcher.update();
|
||||
if let Some(check_watcher) = &state.check_watcher {
|
||||
check_watcher.update();
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
Err(not) => not,
|
||||
|
@ -57,7 +57,7 @@ pub struct WorldState {
|
||||
pub vfs: Arc<RwLock<Vfs>>,
|
||||
pub task_receiver: Receiver<VfsTask>,
|
||||
pub latest_requests: Arc<RwLock<LatestRequests>>,
|
||||
pub check_watcher: CheckWatcher,
|
||||
pub check_watcher: Option<CheckWatcher>,
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user