aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/main_loop.rs104
1 files changed, 59 insertions, 45 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 866d1d176..f349b0810 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -289,55 +289,69 @@ impl GlobalState {
289 } 289 }
290 } 290 }
291 } 291 }
292 Event::Flycheck(task) => match task { 292 Event::Flycheck(mut task) => {
293 flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => { 293 let _p = profile::span("GlobalState::handle_event/flycheck");
294 let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp( 294 loop {
295 &self.config.diagnostics_map, 295 match task {
296 &diagnostic, 296 flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
297 &workspace_root, 297 let diagnostics =
298 ); 298 crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
299 for diag in diagnostics { 299 &self.config.diagnostics_map,
300 match url_to_file_id(&self.vfs.read().0, &diag.url) { 300 &diagnostic,
301 Ok(file_id) => self.diagnostics.add_check_diagnostic( 301 &workspace_root,
302 file_id, 302 );
303 diag.diagnostic, 303 for diag in diagnostics {
304 diag.fixes, 304 match url_to_file_id(&self.vfs.read().0, &diag.url) {
305 ), 305 Ok(file_id) => self.diagnostics.add_check_diagnostic(
306 Err(err) => { 306 file_id,
307 log::error!("File with cargo diagnostic not found in VFS: {}", err); 307 diag.diagnostic,
308 } 308 diag.fixes,
309 }; 309 ),
310 } 310 Err(err) => {
311 } 311 log::error!(
312 312 "File with cargo diagnostic not found in VFS: {}",
313 flycheck::Message::Progress { id, progress } => { 313 err
314 let (state, message) = match progress { 314 );
315 flycheck::Progress::DidStart => { 315 }
316 self.diagnostics.clear_check(); 316 };
317 (Progress::Begin, None)
318 }
319 flycheck::Progress::DidCheckCrate(target) => {
320 (Progress::Report, Some(target))
321 }
322 flycheck::Progress::DidCancel => (Progress::End, None),
323 flycheck::Progress::DidFinish(result) => {
324 if let Err(err) = result {
325 log::error!("cargo check failed: {}", err)
326 } 317 }
327 (Progress::End, None)
328 } 318 }
329 };
330 319
331 // When we're running multiple flychecks, we have to include a disambiguator in 320 flycheck::Message::Progress { id, progress } => {
332 // the title, or the editor complains. Note that this is a user-facing string. 321 let (state, message) = match progress {
333 let title = if self.flycheck.len() == 1 { 322 flycheck::Progress::DidStart => {
334 "cargo check".to_string() 323 self.diagnostics.clear_check();
335 } else { 324 (Progress::Begin, None)
336 format!("cargo check (#{})", id + 1) 325 }
337 }; 326 flycheck::Progress::DidCheckCrate(target) => {
338 self.report_progress(&title, state, message, None); 327 (Progress::Report, Some(target))
328 }
329 flycheck::Progress::DidCancel => (Progress::End, None),
330 flycheck::Progress::DidFinish(result) => {
331 if let Err(err) = result {
332 log::error!("cargo check failed: {}", err)
333 }
334 (Progress::End, None)
335 }
336 };
337
338 // When we're running multiple flychecks, we have to include a disambiguator in
339 // the title, or the editor complains. Note that this is a user-facing string.
340 let title = if self.flycheck.len() == 1 {
341 "cargo check".to_string()
342 } else {
343 format!("cargo check (#{})", id + 1)
344 };
345 self.report_progress(&title, state, message, None);
346 }
347 }
348 // Coalesce many flycheck updates into a single loop turn
349 task = match self.flycheck_receiver.try_recv() {
350 Ok(task) => task,
351 Err(_) => break,
352 }
339 } 353 }
340 }, 354 }
341 } 355 }
342 356
343 let state_changed = self.process_changes(); 357 let state_changed = self.process_changes();