diff options
author | Jonas Schievink <[email protected]> | 2020-09-17 17:50:30 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-09-27 18:41:54 +0100 |
commit | 1a28f30ba48254fae30a29c2f1053f653d5e687e (patch) | |
tree | 66fb358443e69ad81bd9a5331b205891a7d5acfc /crates/rust-analyzer | |
parent | 662ed41ebcb1cd221b32be95d08b5bf5f10ae525 (diff) |
Spawn a flycheck instance per workspace
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 17 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 22 |
3 files changed, 29 insertions, 14 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 212f98a30..96313aaec 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -63,7 +63,7 @@ pub(crate) struct GlobalState { | |||
63 | req_queue: ReqQueue, | 63 | req_queue: ReqQueue, |
64 | pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>, | 64 | pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>, |
65 | pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>, | 65 | pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>, |
66 | pub(crate) flycheck: Option<FlycheckHandle>, | 66 | pub(crate) flycheck: Vec<FlycheckHandle>, |
67 | pub(crate) flycheck_sender: Sender<flycheck::Message>, | 67 | pub(crate) flycheck_sender: Sender<flycheck::Message>, |
68 | pub(crate) flycheck_receiver: Receiver<flycheck::Message>, | 68 | pub(crate) flycheck_receiver: Receiver<flycheck::Message>, |
69 | pub(crate) config: Config, | 69 | pub(crate) config: Config, |
@@ -115,7 +115,7 @@ impl GlobalState { | |||
115 | req_queue: ReqQueue::default(), | 115 | req_queue: ReqQueue::default(), |
116 | task_pool, | 116 | task_pool, |
117 | loader, | 117 | loader, |
118 | flycheck: None, | 118 | flycheck: Vec::new(), |
119 | flycheck_sender, | 119 | flycheck_sender, |
120 | flycheck_receiver, | 120 | flycheck_receiver, |
121 | config, | 121 | config, |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 8d3132581..06ab9d508 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -266,8 +266,8 @@ impl GlobalState { | |||
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | flycheck::Message::Progress(status) => { | 269 | flycheck::Message::Progress { id, progress } => { |
270 | let (state, message) = match status { | 270 | let (state, message) = match progress { |
271 | flycheck::Progress::DidStart => { | 271 | flycheck::Progress::DidStart => { |
272 | self.diagnostics.clear_check(); | 272 | self.diagnostics.clear_check(); |
273 | (Progress::Begin, None) | 273 | (Progress::Begin, None) |
@@ -284,14 +284,21 @@ impl GlobalState { | |||
284 | } | 284 | } |
285 | }; | 285 | }; |
286 | 286 | ||
287 | self.report_progress("cargo check", state, message, None); | 287 | // When we're running multiple flychecks, we have to include a disambiguator in |
288 | // the title, or the editor complains. Note that this is a user-facing string. | ||
289 | let title = if self.flycheck.len() == 1 { | ||
290 | "cargo check".to_string() | ||
291 | } else { | ||
292 | format!("cargo check (#{})", id + 1) | ||
293 | }; | ||
294 | self.report_progress(&title, state, message, None); | ||
288 | } | 295 | } |
289 | }, | 296 | }, |
290 | } | 297 | } |
291 | 298 | ||
292 | let state_changed = self.process_changes(); | 299 | let state_changed = self.process_changes(); |
293 | if prev_status == Status::Loading && self.status == Status::Ready { | 300 | if prev_status == Status::Loading && self.status == Status::Ready { |
294 | if let Some(flycheck) = &self.flycheck { | 301 | for flycheck in &self.flycheck { |
295 | flycheck.update(); | 302 | flycheck.update(); |
296 | } | 303 | } |
297 | } | 304 | } |
@@ -490,7 +497,7 @@ impl GlobalState { | |||
490 | Ok(()) | 497 | Ok(()) |
491 | })? | 498 | })? |
492 | .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| { | 499 | .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| { |
493 | if let Some(flycheck) = &this.flycheck { | 500 | for flycheck in &this.flycheck { |
494 | flycheck.update(); | 501 | flycheck.update(); |
495 | } | 502 | } |
496 | if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) { | 503 | if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) { |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index b070087a4..de0dbcad4 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -235,29 +235,37 @@ impl GlobalState { | |||
235 | let config = match self.config.flycheck.clone() { | 235 | let config = match self.config.flycheck.clone() { |
236 | Some(it) => it, | 236 | Some(it) => it, |
237 | None => { | 237 | None => { |
238 | self.flycheck = None; | 238 | self.flycheck = Vec::new(); |
239 | return; | 239 | return; |
240 | } | 240 | } |
241 | }; | 241 | }; |
242 | 242 | ||
243 | let sender = self.flycheck_sender.clone(); | 243 | let sender = self.flycheck_sender.clone(); |
244 | let sender = Box::new(move |msg| sender.send(msg).unwrap()); | ||
245 | self.flycheck = self | 244 | self.flycheck = self |
246 | .workspaces | 245 | .workspaces |
247 | .iter() | 246 | .iter() |
248 | // FIXME: Figure out the multi-workspace situation | 247 | .enumerate() |
249 | .find_map(|w| match w { | 248 | .filter_map(|(id, w)| match w { |
250 | ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo.workspace_root()), | 249 | ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some((id, cargo.workspace_root())), |
251 | ProjectWorkspace::Json { project, .. } => { | 250 | ProjectWorkspace::Json { project, .. } => { |
252 | // Enable flychecks for json projects if a custom flycheck command was supplied | 251 | // Enable flychecks for json projects if a custom flycheck command was supplied |
253 | // in the workspace configuration. | 252 | // in the workspace configuration. |
254 | match config { | 253 | match config { |
255 | FlycheckConfig::CustomCommand { .. } => Some(project.path()), | 254 | FlycheckConfig::CustomCommand { .. } => Some((id, project.path())), |
256 | _ => None, | 255 | _ => None, |
257 | } | 256 | } |
258 | } | 257 | } |
259 | }) | 258 | }) |
260 | .map(move |root| FlycheckHandle::spawn(sender, config, root.to_path_buf().into())) | 259 | .map(|(id, root)| { |
260 | let sender = sender.clone(); | ||
261 | FlycheckHandle::spawn( | ||
262 | id, | ||
263 | Box::new(move |msg| sender.send(msg).unwrap()), | ||
264 | config.clone(), | ||
265 | root.to_path_buf().into(), | ||
266 | ) | ||
267 | }) | ||
268 | .collect(); | ||
261 | } | 269 | } |
262 | } | 270 | } |
263 | 271 | ||