aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-28 22:33:16 +0000
committerEdwin Cheng <[email protected]>2020-03-28 22:33:16 +0000
commitdc0076de12a1e77515c99b08ee74d0af37b250f8 (patch)
tree29389ab58f1084a3936677ff8cbe1e1e9f42f64e /crates/rust-analyzer/src/main_loop.rs
parent1c2d4135db867efe335a0654d86429bea7bb9caf (diff)
Move roots_to_scan to LoopState
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs35
1 files changed, 19 insertions, 16 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 7825b0077..a96628235 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -208,6 +208,9 @@ pub fn main_loop(
208 ) 208 )
209 }; 209 };
210 210
211 loop_state.roots_to_scan = world_state.vfs.read().n_roots();
212 loop_state.roots_total = loop_state.roots_to_scan;
213
211 let pool = ThreadPool::default(); 214 let pool = ThreadPool::default();
212 let (task_sender, task_receiver) = unbounded::<Task>(); 215 let (task_sender, task_receiver) = unbounded::<Task>();
213 let (libdata_sender, libdata_receiver) = unbounded::<LibraryData>(); 216 let (libdata_sender, libdata_receiver) = unbounded::<LibraryData>();
@@ -333,7 +336,10 @@ struct LoopState {
333 in_flight_libraries: usize, 336 in_flight_libraries: usize,
334 pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>, 337 pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)>,
335 workspace_loaded: bool, 338 workspace_loaded: bool,
339
336 roots_scanned_progress: Option<usize>, 340 roots_scanned_progress: Option<usize>,
341 roots_to_scan: usize,
342 roots_total: usize,
337} 343}
338 344
339impl LoopState { 345impl LoopState {
@@ -377,6 +383,7 @@ fn loop_turn(
377 world_state.add_lib(lib); 383 world_state.add_lib(lib);
378 world_state.maybe_collect_garbage(); 384 world_state.maybe_collect_garbage();
379 loop_state.in_flight_libraries -= 1; 385 loop_state.in_flight_libraries -= 1;
386 loop_state.roots_to_scan -= 1;
380 } 387 }
381 Event::CheckWatcher(task) => on_check_task(task, world_state, task_sender)?, 388 Event::CheckWatcher(task) => on_check_task(task, world_state, task_sender)?,
382 Event::Msg(msg) => match msg { 389 Event::Msg(msg) => match msg {
@@ -408,7 +415,7 @@ fn loop_turn(
408 }; 415 };
409 416
410 let mut state_changed = false; 417 let mut state_changed = false;
411 if let Some(changes) = world_state.process_changes() { 418 if let Some(changes) = world_state.process_changes(&mut loop_state.roots_to_scan) {
412 state_changed = true; 419 state_changed = true;
413 loop_state.pending_libraries.extend(changes); 420 loop_state.pending_libraries.extend(changes);
414 } 421 }
@@ -427,8 +434,11 @@ fn loop_turn(
427 }); 434 });
428 } 435 }
429 436
437 let show_progress = !loop_state.workspace_loaded
438 && world_state.feature_flags.get("notifications.workspace-loaded");
439
430 if !loop_state.workspace_loaded 440 if !loop_state.workspace_loaded
431 && world_state.roots_to_scan == 0 441 && loop_state.roots_to_scan == 0
432 && loop_state.pending_libraries.is_empty() 442 && loop_state.pending_libraries.is_empty()
433 && loop_state.in_flight_libraries == 0 443 && loop_state.in_flight_libraries == 0
434 { 444 {
@@ -439,9 +449,10 @@ fn loop_turn(
439 let snap = world_state.snapshot(); 449 let snap = world_state.snapshot();
440 move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ()) 450 move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ())
441 }); 451 });
442 send_startup_progress(&connection.sender, loop_state, world_state); 452 }
443 } else if !loop_state.workspace_loaded { 453
444 send_startup_progress(&connection.sender, loop_state, world_state); 454 if show_progress {
455 send_startup_progress(&connection.sender, loop_state);
445 } 456 }
446 457
447 if state_changed { 458 if state_changed {
@@ -706,18 +717,10 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender<Message>, state:
706 } 717 }
707} 718}
708 719
709fn send_startup_progress( 720fn send_startup_progress(sender: &Sender<Message>, loop_state: &mut LoopState) {
710 sender: &Sender<Message>, 721 let total: usize = loop_state.roots_total;
711 loop_state: &mut LoopState,
712 world_state: &WorldState,
713) {
714 if !world_state.feature_flags.get("notifications.workspace-loaded") {
715 return;
716 }
717
718 let total: usize = world_state.workspaces.iter().map(|it| it.n_packages()).sum();
719 let prev_progress = loop_state.roots_scanned_progress; 722 let prev_progress = loop_state.roots_scanned_progress;
720 let progress = total - world_state.roots_to_scan; 723 let progress = total - loop_state.roots_to_scan;
721 loop_state.roots_scanned_progress = Some(progress); 724 loop_state.roots_scanned_progress = Some(progress);
722 725
723 match (prev_progress, loop_state.workspace_loaded) { 726 match (prev_progress, loop_state.workspace_loaded) {