From 36812b9d7bd42c6469d857c434a63c921b70bdca Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 30 Mar 2020 02:39:03 +0800 Subject: Fix review comments --- crates/rust-analyzer/src/main_loop.rs | 22 +++++++++++----------- crates/rust-analyzer/src/world.rs | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index a96628235..d35963e95 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -208,8 +208,8 @@ pub fn main_loop( ) }; - loop_state.roots_to_scan = world_state.vfs.read().n_roots(); - loop_state.roots_total = loop_state.roots_to_scan; + loop_state.roots_total = world_state.vfs.read().n_roots(); + loop_state.roots_scanned = 0; let pool = ThreadPool::default(); let (task_sender, task_receiver) = unbounded::(); @@ -337,8 +337,8 @@ struct LoopState { pending_libraries: Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc)>)>, workspace_loaded: bool, - roots_scanned_progress: Option, - roots_to_scan: usize, + roots_progress_reported: Option, + roots_scanned: usize, roots_total: usize, } @@ -383,7 +383,7 @@ fn loop_turn( world_state.add_lib(lib); world_state.maybe_collect_garbage(); loop_state.in_flight_libraries -= 1; - loop_state.roots_to_scan -= 1; + loop_state.roots_scanned += 1; } Event::CheckWatcher(task) => on_check_task(task, world_state, task_sender)?, Event::Msg(msg) => match msg { @@ -415,7 +415,7 @@ fn loop_turn( }; let mut state_changed = false; - if let Some(changes) = world_state.process_changes(&mut loop_state.roots_to_scan) { + if let Some(changes) = world_state.process_changes(&mut loop_state.roots_scanned) { state_changed = true; loop_state.pending_libraries.extend(changes); } @@ -438,7 +438,7 @@ fn loop_turn( && world_state.feature_flags.get("notifications.workspace-loaded"); if !loop_state.workspace_loaded - && loop_state.roots_to_scan == 0 + && loop_state.roots_scanned == loop_state.roots_total && loop_state.pending_libraries.is_empty() && loop_state.in_flight_libraries == 0 { @@ -719,11 +719,11 @@ fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender, state: fn send_startup_progress(sender: &Sender, loop_state: &mut LoopState) { let total: usize = loop_state.roots_total; - let prev_progress = loop_state.roots_scanned_progress; - let progress = total - loop_state.roots_to_scan; - loop_state.roots_scanned_progress = Some(progress); + let prev = loop_state.roots_progress_reported; + let progress = loop_state.roots_scanned; + loop_state.roots_progress_reported = Some(progress); - match (prev_progress, loop_state.workspace_loaded) { + match (prev, loop_state.workspace_loaded) { (None, false) => { let work_done_progress_create = request_new::( loop_state.next_request_id(), diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 01008b09f..5680397ed 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -203,7 +203,7 @@ impl WorldState { /// FIXME: better API here pub fn process_changes( &mut self, - roots_to_scan: &mut usize, + roots_scanned: &mut usize, ) -> Option)>)>> { let changes = self.vfs.write().commit_changes(); if changes.is_empty() { @@ -217,7 +217,7 @@ impl WorldState { let root_path = self.vfs.read().root2path(root); let is_local = self.roots.iter().any(|r| root_path.starts_with(r)); if is_local { - *roots_to_scan -= 1; + *roots_scanned += 1; for (file, path, text) in files { change.add_file(SourceRootId(root.0), FileId(file.0), path, text); } -- cgit v1.2.3