Skip to content

Commit fe2ac44

Browse files
Merge #6656
6656: Coalesce flycheck events r=matklad a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
2 parents 59c4975 + f52abbe commit fe2ac44

File tree

1 file changed

+59
-45
lines changed

1 file changed

+59
-45
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -289,55 +289,69 @@ impl GlobalState {
289289
}
290290
}
291291
}
292-
Event::Flycheck(task) => match task {
293-
flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
294-
let diagnostics = crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
295-
&self.config.diagnostics_map,
296-
&diagnostic,
297-
&workspace_root,
298-
);
299-
for diag in diagnostics {
300-
match url_to_file_id(&self.vfs.read().0, &diag.url) {
301-
Ok(file_id) => self.diagnostics.add_check_diagnostic(
302-
file_id,
303-
diag.diagnostic,
304-
diag.fixes,
305-
),
306-
Err(err) => {
307-
log::error!("File with cargo diagnostic not found in VFS: {}", err);
308-
}
309-
};
310-
}
311-
}
312-
313-
flycheck::Message::Progress { id, progress } => {
314-
let (state, message) = match progress {
315-
flycheck::Progress::DidStart => {
316-
self.diagnostics.clear_check();
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)
292+
Event::Flycheck(mut task) => {
293+
let _p = profile::span("GlobalState::handle_event/flycheck");
294+
loop {
295+
match task {
296+
flycheck::Message::AddDiagnostic { workspace_root, diagnostic } => {
297+
let diagnostics =
298+
crate::diagnostics::to_proto::map_rust_diagnostic_to_lsp(
299+
&self.config.diagnostics_map,
300+
&diagnostic,
301+
&workspace_root,
302+
);
303+
for diag in diagnostics {
304+
match url_to_file_id(&self.vfs.read().0, &diag.url) {
305+
Ok(file_id) => self.diagnostics.add_check_diagnostic(
306+
file_id,
307+
diag.diagnostic,
308+
diag.fixes,
309+
),
310+
Err(err) => {
311+
log::error!(
312+
"File with cargo diagnostic not found in VFS: {}",
313+
err
314+
);
315+
}
316+
};
326317
}
327-
(Progress::End, None)
328318
}
329-
};
330319

331-
// When we're running multiple flychecks, we have to include a disambiguator in
332-
// the title, or the editor complains. Note that this is a user-facing string.
333-
let title = if self.flycheck.len() == 1 {
334-
"cargo check".to_string()
335-
} else {
336-
format!("cargo check (#{})", id + 1)
337-
};
338-
self.report_progress(&title, state, message, None);
320+
flycheck::Message::Progress { id, progress } => {
321+
let (state, message) = match progress {
322+
flycheck::Progress::DidStart => {
323+
self.diagnostics.clear_check();
324+
(Progress::Begin, None)
325+
}
326+
flycheck::Progress::DidCheckCrate(target) => {
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+
}
339353
}
340-
},
354+
}
341355
}
342356

343357
let state_changed = self.process_changes();

0 commit comments

Comments
 (0)