From 9143e3925cd95d30af72745f25e185f65a686d32 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Apr 2021 13:23:09 +0300 Subject: Prepare for more stateless status reporting --- crates/rust-analyzer/src/global_state.rs | 28 +++++++++++++-------- crates/rust-analyzer/src/main_loop.rs | 43 +++++++++++++------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index b9be1e7b8..44a656e62 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -67,21 +67,25 @@ pub(crate) struct GlobalState { req_queue: ReqQueue, pub(crate) task_pool: Handle, Receiver>, pub(crate) loader: Handle, Receiver>, - pub(crate) vfs_config_version: u32, - pub(crate) flycheck: Vec, - pub(crate) flycheck_sender: Sender, - pub(crate) flycheck_receiver: Receiver, pub(crate) config: Arc, pub(crate) analysis_host: AnalysisHost, pub(crate) diagnostics: DiagnosticCollection, pub(crate) mem_docs: FxHashMap, pub(crate) semantic_tokens_cache: Arc>>, - pub(crate) vfs: Arc)>>, pub(crate) shutdown_requested: bool, pub(crate) status: Status, pub(crate) source_root_config: SourceRootConfig, pub(crate) proc_macro_client: Option, + pub(crate) flycheck: Vec, + pub(crate) flycheck_sender: Sender, + pub(crate) flycheck_receiver: Receiver, + + pub(crate) vfs: Arc)>>, + pub(crate) vfs_config_version: u32, + pub(crate) vfs_progress_n_total: usize, + pub(crate) vfs_progress_n_done: usize, + /// For both `workspaces` and `workspace_build_data`, the field stores the /// data we actually use, while the `OpQueue` stores the result of the last /// fetch. @@ -129,23 +133,27 @@ impl GlobalState { GlobalState { sender, req_queue: ReqQueue::default(), - vfs_config_version: 0, task_pool, loader, - flycheck: Vec::new(), - flycheck_sender, - flycheck_receiver, config: Arc::new(config), analysis_host, diagnostics: Default::default(), mem_docs: FxHashMap::default(), semantic_tokens_cache: Arc::new(Default::default()), - vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), shutdown_requested: false, status: Status::default(), source_root_config: SourceRootConfig::default(), proc_macro_client: None, + flycheck: Vec::new(), + flycheck_sender, + flycheck_receiver, + + vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), + vfs_config_version: 0, + vfs_progress_n_total: 0, + vfs_progress_n_done: 0, + workspaces: Arc::new(Vec::new()), fetch_workspaces_queue: OpQueue::default(), workspace_build_data: None, diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 7e96f3c4a..4a4705e1f 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -314,31 +314,23 @@ impl GlobalState { } } vfs::loader::Message::Progress { n_total, n_done, config_version } => { + self.vfs_progress_n_total = n_total; + self.vfs_progress_n_done = n_done; always!(config_version <= self.vfs_config_version); - if n_total == 0 { - new_status = Status::Invalid; + let state = if n_done == 0 { + Progress::Begin + } else if n_done < n_total { + Progress::Report } else { - let state = if n_done == 0 { - new_status = Status::Loading; - Progress::Begin - } else if n_done < n_total { - Progress::Report - } else { - assert_eq!(n_done, n_total); - new_status = Status::Ready { - partial: self.config.run_build_scripts() - && self.workspace_build_data.is_none() - || config_version < self.vfs_config_version, - }; - Progress::End - }; - self.report_progress( - "roots scanned", - state, - Some(format!("{}/{}", n_done, n_total)), - Some(Progress::fraction(n_done, n_total)), - ) - } + assert_eq!(n_done, n_total); + Progress::End + }; + self.report_progress( + "roots scanned", + state, + Some(format!("{}/{}", n_done, n_total)), + Some(Progress::fraction(n_done, n_total)), + ) } } // Coalesce many VFS event into a single loop turn @@ -497,8 +489,9 @@ impl GlobalState { RequestDispatcher { req: Some(req), global_state: self } .on_sync::(|s, ()| { - self.fetch_workspaces_request(); - self.fetch_workspaces_if_needed(); + s.fetch_workspaces_request(); + s.fetch_workspaces_if_needed(); + Ok(()) })? .on_sync::(|s, p| handlers::handle_join_lines(s.snapshot(), p))? .on_sync::(|s, p| handlers::handle_on_enter(s.snapshot(), p))? -- cgit v1.2.3