From 6da651f5dae29234516453b10f806cc4c8a319f1 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 2 Dec 2020 20:18:28 +0100 Subject: Don't prime caches when just opening a file --- crates/rust-analyzer/src/main_loop.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index f349b0810..55d46b09e 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -506,7 +506,7 @@ impl GlobalState { .write() .0 .set_file_contents(path, Some(params.text_document.text.into_bytes())); - this.update_file_notifications_on_threadpool(); + this.maybe_update_diagnostics(); } Ok(()) })? @@ -616,6 +616,23 @@ impl GlobalState { Ok(()) } fn update_file_notifications_on_threadpool(&mut self) { + self.maybe_update_diagnostics(); + self.task_pool.handle.spawn_with_sender({ + let snap = self.snapshot(); + move |sender| { + snap.analysis + .prime_caches(|progress| { + sender.send(Task::PrimeCaches(progress)).unwrap(); + }) + .unwrap_or_else(|_: Canceled| { + // Pretend that we're done, so that the progress bar is removed. Otherwise + // the editor may complain about it already existing. + sender.send(Task::PrimeCaches(PrimeCachesProgress::Finished)).unwrap() + }); + } + }); + } + fn maybe_update_diagnostics(&mut self) { let subscriptions = self .mem_docs .keys() @@ -644,19 +661,5 @@ impl GlobalState { Task::Diagnostics(diagnostics) }) } - self.task_pool.handle.spawn_with_sender({ - let snap = self.snapshot(); - move |sender| { - snap.analysis - .prime_caches(|progress| { - sender.send(Task::PrimeCaches(progress)).unwrap(); - }) - .unwrap_or_else(|_: Canceled| { - // Pretend that we're done, so that the progress bar is removed. Otherwise - // the editor may complain about it already existing. - sender.send(Task::PrimeCaches(PrimeCachesProgress::Finished)).unwrap() - }); - } - }); } } -- cgit v1.2.3