diff options
author | Boris-Chengbiao Zhou <[email protected]> | 2021-04-29 20:12:48 +0100 |
---|---|---|
committer | Boris-Chengbiao Zhou <[email protected]> | 2021-04-30 15:48:11 +0100 |
commit | ce8c6c47626c3fee3ca49fb3aec4f2c588b3db7a (patch) | |
tree | edef60a908a63d56487488a4e4a146f6f0e0d57b /crates/rust-analyzer/src/main_loop.rs | |
parent | 80bee14e14f67f02746befff77a8a4bbfd3e5849 (diff) |
Ensure that only one cache priming task can run at a time
Fixes #8632.
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index a766aacad..a3e974e92 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -278,6 +278,8 @@ impl GlobalState { | |||
278 | }; | 278 | }; |
279 | } | 279 | } |
280 | 280 | ||
281 | let mut finished = false; | ||
282 | |||
281 | for progress in prime_caches_progress { | 283 | for progress in prime_caches_progress { |
282 | let (state, message, fraction); | 284 | let (state, message, fraction); |
283 | match progress { | 285 | match progress { |
@@ -295,11 +297,18 @@ impl GlobalState { | |||
295 | state = Progress::End; | 297 | state = Progress::End; |
296 | message = None; | 298 | message = None; |
297 | fraction = 1.0; | 299 | fraction = 1.0; |
300 | finished = true; | ||
298 | } | 301 | } |
299 | }; | 302 | }; |
300 | 303 | ||
301 | self.report_progress("Indexing", state, message, Some(fraction)); | 304 | self.report_progress("Indexing", state, message, Some(fraction)); |
302 | } | 305 | } |
306 | |||
307 | // If the task is cancelled we may observe two `PrimeCachesProgress::Finished` so we | ||
308 | // have to make sure to only call `op_completed()` once. | ||
309 | if finished { | ||
310 | self.prime_caches_queue.op_completed(()); | ||
311 | } | ||
303 | } | 312 | } |
304 | Event::Vfs(mut task) => { | 313 | Event::Vfs(mut task) => { |
305 | let _p = profile::span("GlobalState::handle_event/vfs"); | 314 | let _p = profile::span("GlobalState::handle_event/vfs"); |
@@ -711,6 +720,13 @@ impl GlobalState { | |||
711 | } | 720 | } |
712 | fn update_file_notifications_on_threadpool(&mut self) { | 721 | fn update_file_notifications_on_threadpool(&mut self) { |
713 | self.maybe_update_diagnostics(); | 722 | self.maybe_update_diagnostics(); |
723 | |||
724 | // Ensure that only one cache priming task can run at a time | ||
725 | self.prime_caches_queue.request_op(()); | ||
726 | if self.prime_caches_queue.should_start_op().is_none() { | ||
727 | return; | ||
728 | } | ||
729 | |||
714 | self.task_pool.handle.spawn_with_sender({ | 730 | self.task_pool.handle.spawn_with_sender({ |
715 | let snap = self.snapshot(); | 731 | let snap = self.snapshot(); |
716 | move |sender| { | 732 | move |sender| { |