From 298adb27b9642adcb566d1e3b709a444d0b0ef06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 16:01:03 +0200 Subject: Better account for project reload --- crates/rust-analyzer/src/global_state.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index b8aa1e5b5..b7b4edf66 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -27,7 +27,7 @@ use crate::{ Result, }; -#[derive(Eq, PartialEq)] +#[derive(Eq, PartialEq, Copy, Clone)] pub(crate) enum Status { Loading, Ready, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index e3d49d24d..e03038b25 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -136,7 +136,7 @@ impl GlobalState { log::info!("queued count = {}", queue_count); } - let mut became_ready = false; + let prev_status = self.status; match event { Event::Lsp(msg) => match msg { lsp_server::Message::Request(req) => self.on_request(loop_start, req)?, @@ -168,15 +168,17 @@ impl GlobalState { } } vfs::loader::Message::Progress { n_total, n_done } => { - if n_total > 0 { + if n_total == 0 { + self.status = Status::Ready; + } else { let state = if n_done == 0 { + self.status = Status::Loading; Progress::Begin } else if n_done < n_total { Progress::Report } else { assert_eq!(n_done, n_total); self.status = Status::Ready; - became_ready = true; Progress::End }; self.report_progress( @@ -233,13 +235,13 @@ impl GlobalState { } let state_changed = self.process_changes(); - if became_ready { + if prev_status == Status::Loading && self.status == Status::Ready { if let Some(flycheck) = &self.flycheck { flycheck.handle.update(); } } - if self.status == Status::Ready && (state_changed || became_ready) { + if self.status == Status::Ready && (state_changed || prev_status == Status::Loading) { let subscriptions = self .mem_docs .iter() -- cgit v1.2.3