File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ pub(crate) struct GlobalState {
8484 pub ( crate ) workspace_build_data : Option < BuildDataResult > ,
8585 pub ( crate ) fetch_build_data_queue :
8686 OpQueue < BuildDataCollector , Option < anyhow:: Result < BuildDataResult > > > ,
87+ pub ( crate ) prime_caches_queue : OpQueue < ( ) , ( ) > ,
8788
8889 latest_requests : Arc < RwLock < LatestRequests > > ,
8990}
@@ -146,6 +147,7 @@ impl GlobalState {
146147 workspaces : Arc :: new ( Vec :: new ( ) ) ,
147148 fetch_workspaces_queue : OpQueue :: default ( ) ,
148149 workspace_build_data : None ,
150+ prime_caches_queue : OpQueue :: default ( ) ,
149151
150152 fetch_build_data_queue : OpQueue :: default ( ) ,
151153 latest_requests : Default :: default ( ) ,
Original file line number Diff line number Diff line change @@ -278,6 +278,8 @@ impl GlobalState {
278278 } ;
279279 }
280280
281+ let mut finished = false ;
282+
281283 for progress in prime_caches_progress {
282284 let ( state, message, fraction) ;
283285 match progress {
@@ -295,11 +297,18 @@ impl GlobalState {
295297 state = Progress :: End ;
296298 message = None ;
297299 fraction = 1.0 ;
300+ finished = true ;
298301 }
299302 } ;
300303
301304 self . report_progress ( "Indexing" , state, message, Some ( fraction) ) ;
302305 }
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+ }
303312 }
304313 Event :: Vfs ( mut task) => {
305314 let _p = profile:: span ( "GlobalState::handle_event/vfs" ) ;
@@ -711,6 +720,13 @@ impl GlobalState {
711720 }
712721 fn update_file_notifications_on_threadpool ( & mut self ) {
713722 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+
714730 self . task_pool . handle . spawn_with_sender ( {
715731 let snap = self . snapshot ( ) ;
716732 move |sender| {
You can’t perform that action at this time.
0 commit comments