From dda942debe0ea178f07b75989b2ba6942786e218 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Apr 2020 11:01:37 +0200 Subject: Pull enabled check up --- crates/ra_flycheck/src/lib.rs | 4 ---- crates/rust-analyzer/src/main_loop.rs | 13 ++++++++----- crates/rust-analyzer/src/world.rs | 6 ++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index f6f9171ad..b6bb9da4b 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs @@ -24,7 +24,6 @@ pub use crate::conv::url_from_path_with_drive_lowercasing; #[derive(Clone, Debug)] pub struct CheckConfig { - pub enable: bool, pub args: Vec, pub command: String, pub all_targets: bool, @@ -216,9 +215,6 @@ impl CheckWatcherThread { // First, clear and cancel the old thread self.message_recv = never(); self.check_process = None; - if !self.options.enable { - return; - } let mut args: Vec = vec![ self.options.command.clone(), diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index bb33fb27d..16d7f1569 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -101,11 +101,14 @@ fn get_config( chaining_hints: config.inlay_hints_chaining, max_length: config.inlay_hints_max_length, }, - check: CheckConfig { - enable: config.cargo_watch_enable, - args: config.cargo_watch_args.clone(), - command: config.cargo_watch_command.clone(), - all_targets: config.cargo_watch_all_targets, + check: if config.cargo_watch_enable { + Some(CheckConfig { + args: config.cargo_watch_args.clone(), + command: config.cargo_watch_command.clone(), + all_targets: config.cargo_watch_all_targets, + }) + } else { + None }, rustfmt_args: config.rustfmt_args.clone(), vscode_lldb: config.vscode_lldb, diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index acb729bae..9a4e353fb 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -32,6 +32,8 @@ use ra_db::ExternSourceId; use rustc_hash::{FxHashMap, FxHashSet}; fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option { + let check_config = config.check.as_ref()?; + // FIXME: Figure out the multi-workspace situation workspaces .iter() @@ -41,7 +43,7 @@ fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option, - pub check: CheckConfig, + pub check: Option, pub vscode_lldb: bool, pub proc_macro_srv: Option, } -- cgit v1.2.3 From 3990d971e54b69949f26bbbc530fa22fdc2fcd7f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Apr 2020 11:09:19 +0200 Subject: Crisper name https://www.flycheck.org/en/latest/ --- crates/ra_flycheck/src/lib.rs | 20 ++++++++++---------- crates/rust-analyzer/src/main_loop.rs | 10 +++++----- crates/rust-analyzer/src/world.rs | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index b6bb9da4b..2990c1f95 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs @@ -29,27 +29,27 @@ pub struct CheckConfig { pub all_targets: bool, } -/// CheckWatcher wraps the shared state and communication machinery used for +/// Flycheck wraps the shared state and communication machinery used for /// running `cargo check` (or other compatible command) and providing /// diagnostics based on the output. /// The spawned thread is shut down when this struct is dropped. #[derive(Debug)] -pub struct CheckWatcher { +pub struct Flycheck { // XXX: drop order is significant cmd_send: Sender, handle: Option>, pub task_recv: Receiver, } -impl CheckWatcher { - pub fn new(config: CheckConfig, workspace_root: PathBuf) -> CheckWatcher { +impl Flycheck { + pub fn new(config: CheckConfig, workspace_root: PathBuf) -> Flycheck { let (task_send, task_recv) = unbounded::(); let (cmd_send, cmd_recv) = unbounded::(); let handle = jod_thread::spawn(move || { - let mut check = CheckWatcherThread::new(config, workspace_root); + let mut check = FlycheckThread::new(config, workspace_root); check.run(&task_send, &cmd_recv); }); - CheckWatcher { task_recv, cmd_send, handle: Some(handle) } + Flycheck { task_recv, cmd_send, handle: Some(handle) } } /// Schedule a re-start of the cargo check worker. @@ -75,7 +75,7 @@ pub enum CheckCommand { Update, } -struct CheckWatcherThread { +struct FlycheckThread { options: CheckConfig, workspace_root: PathBuf, last_update_req: Option, @@ -89,9 +89,9 @@ struct CheckWatcherThread { check_process: Option>, } -impl CheckWatcherThread { - fn new(options: CheckConfig, workspace_root: PathBuf) -> CheckWatcherThread { - CheckWatcherThread { +impl FlycheckThread { + fn new(options: CheckConfig, workspace_root: PathBuf) -> FlycheckThread { + FlycheckThread { options, workspace_root, last_update_req: None, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 16d7f1569..79dc03de4 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -243,7 +243,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.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { + recv(world_state.flycheck.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()), } @@ -484,8 +484,8 @@ fn loop_turn( && loop_state.in_flight_libraries == 0 { loop_state.workspace_loaded = true; - if let Some(check_watcher) = &world_state.check_watcher { - check_watcher.update(); + if let Some(flycheck) = &world_state.flycheck { + flycheck.update(); } pool.execute({ let subs = loop_state.subscriptions.subscriptions(); @@ -657,8 +657,8 @@ fn on_notification( }; let not = match notification_cast::(not) { Ok(_params) => { - if let Some(check_watcher) = &state.check_watcher { - check_watcher.update(); + if let Some(flycheck) = &state.flycheck { + flycheck.update(); } return Ok(()); } diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 9a4e353fb..7814a682e 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -11,7 +11,7 @@ use std::{ use crossbeam_channel::{unbounded, Receiver}; use lsp_types::Url; use parking_lot::RwLock; -use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, CheckWatcher}; +use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, Flycheck}; use ra_ide::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData, SourceRootId, @@ -31,7 +31,7 @@ use crate::{ use ra_db::ExternSourceId; use rustc_hash::{FxHashMap, FxHashSet}; -fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option { +fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option { let check_config = config.check.as_ref()?; // FIXME: Figure out the multi-workspace situation @@ -43,7 +43,7 @@ fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option>, pub task_receiver: Receiver, pub latest_requests: Arc>, - pub check_watcher: Option, + pub flycheck: Option, pub diagnostics: DiagnosticCollection, } @@ -203,7 +203,7 @@ impl WorldState { }); change.set_crate_graph(crate_graph); - let check_watcher = create_watcher(&workspaces, &config); + let flycheck = create_flycheck(&workspaces, &config); let mut analysis_host = AnalysisHost::new(lru_capacity); analysis_host.apply_change(change); @@ -216,7 +216,7 @@ impl WorldState { vfs: Arc::new(RwLock::new(vfs)), task_receiver, latest_requests: Default::default(), - check_watcher, + flycheck, diagnostics: Default::default(), } } @@ -229,7 +229,7 @@ impl WorldState { ) { self.feature_flags = Arc::new(feature_flags); self.analysis_host.update_lru_capacity(lru_capacity); - self.check_watcher = create_watcher(&self.workspaces, &config); + self.flycheck = create_flycheck(&self.workspaces, &config); self.config = config; } -- cgit v1.2.3 From b5306ea70659aad28b1a5de248128b47a5e5f1bf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Apr 2020 11:16:43 +0200 Subject: Simplify --- crates/ra_flycheck/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index 2990c1f95..75aece45f 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs @@ -37,7 +37,7 @@ pub struct CheckConfig { pub struct Flycheck { // XXX: drop order is significant cmd_send: Sender, - handle: Option>, + handle: jod_thread::JoinHandle<()>, pub task_recv: Receiver, } @@ -49,7 +49,7 @@ impl Flycheck { let mut check = FlycheckThread::new(config, workspace_root); check.run(&task_send, &cmd_recv); }); - Flycheck { task_recv, cmd_send, handle: Some(handle) } + Flycheck { task_recv, cmd_send, handle } } /// Schedule a re-start of the cargo check worker. -- cgit v1.2.3