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 | |
parent | 80bee14e14f67f02746befff77a8a4bbfd3e5849 (diff) |
Ensure that only one cache priming task can run at a time
Fixes #8632.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index adeb7a97e..6f2f482c1 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -84,6 +84,7 @@ pub(crate) struct GlobalState { | |||
84 | pub(crate) workspace_build_data: Option<BuildDataResult>, | 84 | pub(crate) workspace_build_data: Option<BuildDataResult>, |
85 | pub(crate) fetch_build_data_queue: | 85 | pub(crate) fetch_build_data_queue: |
86 | OpQueue<BuildDataCollector, Option<anyhow::Result<BuildDataResult>>>, | 86 | OpQueue<BuildDataCollector, Option<anyhow::Result<BuildDataResult>>>, |
87 | pub(crate) prime_caches_queue: OpQueue<(), ()>, | ||
87 | 88 | ||
88 | latest_requests: Arc<RwLock<LatestRequests>>, | 89 | latest_requests: Arc<RwLock<LatestRequests>>, |
89 | } | 90 | } |
@@ -146,6 +147,7 @@ impl GlobalState { | |||
146 | workspaces: Arc::new(Vec::new()), | 147 | workspaces: Arc::new(Vec::new()), |
147 | fetch_workspaces_queue: OpQueue::default(), | 148 | fetch_workspaces_queue: OpQueue::default(), |
148 | workspace_build_data: None, | 149 | workspace_build_data: None, |
150 | prime_caches_queue: OpQueue::default(), | ||
149 | 151 | ||
150 | fetch_build_data_queue: OpQueue::default(), | 152 | fetch_build_data_queue: OpQueue::default(), |
151 | latest_requests: Default::default(), | 153 | latest_requests: Default::default(), |
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| { |