diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-01 10:17:09 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-01 10:17:09 +0100 |
commit | 8cce752bcb83c86f300c9a8e830dd7d411f6bc48 (patch) | |
tree | eca5f6bd69dc7f7f0df5a3a4ab5ed47f5aa7255e | |
parent | fae6cecf5434a865043ec566a6417e9bb28c3a4c (diff) | |
parent | b5306ea70659aad28b1a5de248128b47a5e5f1bf (diff) |
Merge #3802
3802: Crisper name r=matklad a=matklad
https://www.flycheck.org/en/latest/
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_flycheck/src/lib.rs | 26 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 23 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 18 |
3 files changed, 34 insertions, 33 deletions
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs index f6f9171ad..75aece45f 100644 --- a/crates/ra_flycheck/src/lib.rs +++ b/crates/ra_flycheck/src/lib.rs | |||
@@ -24,33 +24,32 @@ pub use crate::conv::url_from_path_with_drive_lowercasing; | |||
24 | 24 | ||
25 | #[derive(Clone, Debug)] | 25 | #[derive(Clone, Debug)] |
26 | pub struct CheckConfig { | 26 | pub struct CheckConfig { |
27 | pub enable: bool, | ||
28 | pub args: Vec<String>, | 27 | pub args: Vec<String>, |
29 | pub command: String, | 28 | pub command: String, |
30 | pub all_targets: bool, | 29 | pub all_targets: bool, |
31 | } | 30 | } |
32 | 31 | ||
33 | /// CheckWatcher wraps the shared state and communication machinery used for | 32 | /// Flycheck wraps the shared state and communication machinery used for |
34 | /// running `cargo check` (or other compatible command) and providing | 33 | /// running `cargo check` (or other compatible command) and providing |
35 | /// diagnostics based on the output. | 34 | /// diagnostics based on the output. |
36 | /// The spawned thread is shut down when this struct is dropped. | 35 | /// The spawned thread is shut down when this struct is dropped. |
37 | #[derive(Debug)] | 36 | #[derive(Debug)] |
38 | pub struct CheckWatcher { | 37 | pub struct Flycheck { |
39 | // XXX: drop order is significant | 38 | // XXX: drop order is significant |
40 | cmd_send: Sender<CheckCommand>, | 39 | cmd_send: Sender<CheckCommand>, |
41 | handle: Option<jod_thread::JoinHandle<()>>, | 40 | handle: jod_thread::JoinHandle<()>, |
42 | pub task_recv: Receiver<CheckTask>, | 41 | pub task_recv: Receiver<CheckTask>, |
43 | } | 42 | } |
44 | 43 | ||
45 | impl CheckWatcher { | 44 | impl Flycheck { |
46 | pub fn new(config: CheckConfig, workspace_root: PathBuf) -> CheckWatcher { | 45 | pub fn new(config: CheckConfig, workspace_root: PathBuf) -> Flycheck { |
47 | let (task_send, task_recv) = unbounded::<CheckTask>(); | 46 | let (task_send, task_recv) = unbounded::<CheckTask>(); |
48 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); | 47 | let (cmd_send, cmd_recv) = unbounded::<CheckCommand>(); |
49 | let handle = jod_thread::spawn(move || { | 48 | let handle = jod_thread::spawn(move || { |
50 | let mut check = CheckWatcherThread::new(config, workspace_root); | 49 | let mut check = FlycheckThread::new(config, workspace_root); |
51 | check.run(&task_send, &cmd_recv); | 50 | check.run(&task_send, &cmd_recv); |
52 | }); | 51 | }); |
53 | CheckWatcher { task_recv, cmd_send, handle: Some(handle) } | 52 | Flycheck { task_recv, cmd_send, handle } |
54 | } | 53 | } |
55 | 54 | ||
56 | /// Schedule a re-start of the cargo check worker. | 55 | /// Schedule a re-start of the cargo check worker. |
@@ -76,7 +75,7 @@ pub enum CheckCommand { | |||
76 | Update, | 75 | Update, |
77 | } | 76 | } |
78 | 77 | ||
79 | struct CheckWatcherThread { | 78 | struct FlycheckThread { |
80 | options: CheckConfig, | 79 | options: CheckConfig, |
81 | workspace_root: PathBuf, | 80 | workspace_root: PathBuf, |
82 | last_update_req: Option<Instant>, | 81 | last_update_req: Option<Instant>, |
@@ -90,9 +89,9 @@ struct CheckWatcherThread { | |||
90 | check_process: Option<jod_thread::JoinHandle<()>>, | 89 | check_process: Option<jod_thread::JoinHandle<()>>, |
91 | } | 90 | } |
92 | 91 | ||
93 | impl CheckWatcherThread { | 92 | impl FlycheckThread { |
94 | fn new(options: CheckConfig, workspace_root: PathBuf) -> CheckWatcherThread { | 93 | fn new(options: CheckConfig, workspace_root: PathBuf) -> FlycheckThread { |
95 | CheckWatcherThread { | 94 | FlycheckThread { |
96 | options, | 95 | options, |
97 | workspace_root, | 96 | workspace_root, |
98 | last_update_req: None, | 97 | last_update_req: None, |
@@ -216,9 +215,6 @@ impl CheckWatcherThread { | |||
216 | // First, clear and cancel the old thread | 215 | // First, clear and cancel the old thread |
217 | self.message_recv = never(); | 216 | self.message_recv = never(); |
218 | self.check_process = None; | 217 | self.check_process = None; |
219 | if !self.options.enable { | ||
220 | return; | ||
221 | } | ||
222 | 218 | ||
223 | let mut args: Vec<String> = vec![ | 219 | let mut args: Vec<String> = vec![ |
224 | self.options.command.clone(), | 220 | self.options.command.clone(), |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index bb33fb27d..79dc03de4 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -101,11 +101,14 @@ fn get_config( | |||
101 | chaining_hints: config.inlay_hints_chaining, | 101 | chaining_hints: config.inlay_hints_chaining, |
102 | max_length: config.inlay_hints_max_length, | 102 | max_length: config.inlay_hints_max_length, |
103 | }, | 103 | }, |
104 | check: CheckConfig { | 104 | check: if config.cargo_watch_enable { |
105 | enable: config.cargo_watch_enable, | 105 | Some(CheckConfig { |
106 | args: config.cargo_watch_args.clone(), | 106 | args: config.cargo_watch_args.clone(), |
107 | command: config.cargo_watch_command.clone(), | 107 | command: config.cargo_watch_command.clone(), |
108 | all_targets: config.cargo_watch_all_targets, | 108 | all_targets: config.cargo_watch_all_targets, |
109 | }) | ||
110 | } else { | ||
111 | None | ||
109 | }, | 112 | }, |
110 | rustfmt_args: config.rustfmt_args.clone(), | 113 | rustfmt_args: config.rustfmt_args.clone(), |
111 | vscode_lldb: config.vscode_lldb, | 114 | vscode_lldb: config.vscode_lldb, |
@@ -240,7 +243,7 @@ pub fn main_loop( | |||
240 | Err(RecvError) => return Err("vfs died".into()), | 243 | Err(RecvError) => return Err("vfs died".into()), |
241 | }, | 244 | }, |
242 | recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), | 245 | recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), |
243 | recv(world_state.check_watcher.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { | 246 | recv(world_state.flycheck.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { |
244 | Ok(task) => Event::CheckWatcher(task), | 247 | Ok(task) => Event::CheckWatcher(task), |
245 | Err(RecvError) => return Err("check watcher died".into()), | 248 | Err(RecvError) => return Err("check watcher died".into()), |
246 | } | 249 | } |
@@ -481,8 +484,8 @@ fn loop_turn( | |||
481 | && loop_state.in_flight_libraries == 0 | 484 | && loop_state.in_flight_libraries == 0 |
482 | { | 485 | { |
483 | loop_state.workspace_loaded = true; | 486 | loop_state.workspace_loaded = true; |
484 | if let Some(check_watcher) = &world_state.check_watcher { | 487 | if let Some(flycheck) = &world_state.flycheck { |
485 | check_watcher.update(); | 488 | flycheck.update(); |
486 | } | 489 | } |
487 | pool.execute({ | 490 | pool.execute({ |
488 | let subs = loop_state.subscriptions.subscriptions(); | 491 | let subs = loop_state.subscriptions.subscriptions(); |
@@ -654,8 +657,8 @@ fn on_notification( | |||
654 | }; | 657 | }; |
655 | let not = match notification_cast::<req::DidSaveTextDocument>(not) { | 658 | let not = match notification_cast::<req::DidSaveTextDocument>(not) { |
656 | Ok(_params) => { | 659 | Ok(_params) => { |
657 | if let Some(check_watcher) = &state.check_watcher { | 660 | if let Some(flycheck) = &state.flycheck { |
658 | check_watcher.update(); | 661 | flycheck.update(); |
659 | } | 662 | } |
660 | return Ok(()); | 663 | return Ok(()); |
661 | } | 664 | } |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index acb729bae..7814a682e 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -11,7 +11,7 @@ use std::{ | |||
11 | use crossbeam_channel::{unbounded, Receiver}; | 11 | use crossbeam_channel::{unbounded, Receiver}; |
12 | use lsp_types::Url; | 12 | use lsp_types::Url; |
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, CheckWatcher}; | 14 | use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckConfig, Flycheck}; |
15 | use ra_ide::{ | 15 | use ra_ide::{ |
16 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData, | 16 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsConfig, LibraryData, |
17 | SourceRootId, | 17 | SourceRootId, |
@@ -31,7 +31,9 @@ use crate::{ | |||
31 | use ra_db::ExternSourceId; | 31 | use ra_db::ExternSourceId; |
32 | use rustc_hash::{FxHashMap, FxHashSet}; | 32 | use rustc_hash::{FxHashMap, FxHashSet}; |
33 | 33 | ||
34 | fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option<CheckWatcher> { | 34 | fn create_flycheck(workspaces: &[ProjectWorkspace], config: &Config) -> Option<Flycheck> { |
35 | let check_config = config.check.as_ref()?; | ||
36 | |||
35 | // FIXME: Figure out the multi-workspace situation | 37 | // FIXME: Figure out the multi-workspace situation |
36 | workspaces | 38 | workspaces |
37 | .iter() | 39 | .iter() |
@@ -41,7 +43,7 @@ fn create_watcher(workspaces: &[ProjectWorkspace], config: &Config) -> Option<Ch | |||
41 | }) | 43 | }) |
42 | .map(|cargo| { | 44 | .map(|cargo| { |
43 | let cargo_project_root = cargo.workspace_root().to_path_buf(); | 45 | let cargo_project_root = cargo.workspace_root().to_path_buf(); |
44 | Some(CheckWatcher::new(config.check.clone(), cargo_project_root)) | 46 | Some(Flycheck::new(check_config.clone(), cargo_project_root)) |
45 | }) | 47 | }) |
46 | .unwrap_or_else(|| { | 48 | .unwrap_or_else(|| { |
47 | log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); | 49 | log::warn!("Cargo check watching only supported for cargo workspaces, disabling"); |
@@ -56,7 +58,7 @@ pub struct Config { | |||
56 | pub line_folding_only: bool, | 58 | pub line_folding_only: bool, |
57 | pub inlay_hints: InlayHintsConfig, | 59 | pub inlay_hints: InlayHintsConfig, |
58 | pub rustfmt_args: Vec<String>, | 60 | pub rustfmt_args: Vec<String>, |
59 | pub check: CheckConfig, | 61 | pub check: Option<CheckConfig>, |
60 | pub vscode_lldb: bool, | 62 | pub vscode_lldb: bool, |
61 | pub proc_macro_srv: Option<String>, | 63 | pub proc_macro_srv: Option<String>, |
62 | } | 64 | } |
@@ -76,7 +78,7 @@ pub struct WorldState { | |||
76 | pub vfs: Arc<RwLock<Vfs>>, | 78 | pub vfs: Arc<RwLock<Vfs>>, |
77 | pub task_receiver: Receiver<VfsTask>, | 79 | pub task_receiver: Receiver<VfsTask>, |
78 | pub latest_requests: Arc<RwLock<LatestRequests>>, | 80 | pub latest_requests: Arc<RwLock<LatestRequests>>, |
79 | pub check_watcher: Option<CheckWatcher>, | 81 | pub flycheck: Option<Flycheck>, |
80 | pub diagnostics: DiagnosticCollection, | 82 | pub diagnostics: DiagnosticCollection, |
81 | } | 83 | } |
82 | 84 | ||
@@ -201,7 +203,7 @@ impl WorldState { | |||
201 | }); | 203 | }); |
202 | change.set_crate_graph(crate_graph); | 204 | change.set_crate_graph(crate_graph); |
203 | 205 | ||
204 | let check_watcher = create_watcher(&workspaces, &config); | 206 | let flycheck = create_flycheck(&workspaces, &config); |
205 | 207 | ||
206 | let mut analysis_host = AnalysisHost::new(lru_capacity); | 208 | let mut analysis_host = AnalysisHost::new(lru_capacity); |
207 | analysis_host.apply_change(change); | 209 | analysis_host.apply_change(change); |
@@ -214,7 +216,7 @@ impl WorldState { | |||
214 | vfs: Arc::new(RwLock::new(vfs)), | 216 | vfs: Arc::new(RwLock::new(vfs)), |
215 | task_receiver, | 217 | task_receiver, |
216 | latest_requests: Default::default(), | 218 | latest_requests: Default::default(), |
217 | check_watcher, | 219 | flycheck, |
218 | diagnostics: Default::default(), | 220 | diagnostics: Default::default(), |
219 | } | 221 | } |
220 | } | 222 | } |
@@ -227,7 +229,7 @@ impl WorldState { | |||
227 | ) { | 229 | ) { |
228 | self.feature_flags = Arc::new(feature_flags); | 230 | self.feature_flags = Arc::new(feature_flags); |
229 | self.analysis_host.update_lru_capacity(lru_capacity); | 231 | self.analysis_host.update_lru_capacity(lru_capacity); |
230 | self.check_watcher = create_watcher(&self.workspaces, &config); | 232 | self.flycheck = create_flycheck(&self.workspaces, &config); |
231 | self.config = config; | 233 | self.config = config; |
232 | } | 234 | } |
233 | 235 | ||