diff options
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 28 | ||||
-rw-r--r-- | 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 { | |||
67 | req_queue: ReqQueue, | 67 | req_queue: ReqQueue, |
68 | pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>, | 68 | pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>, |
69 | pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>, | 69 | pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>, |
70 | pub(crate) vfs_config_version: u32, | ||
71 | pub(crate) flycheck: Vec<FlycheckHandle>, | ||
72 | pub(crate) flycheck_sender: Sender<flycheck::Message>, | ||
73 | pub(crate) flycheck_receiver: Receiver<flycheck::Message>, | ||
74 | pub(crate) config: Arc<Config>, | 70 | pub(crate) config: Arc<Config>, |
75 | pub(crate) analysis_host: AnalysisHost, | 71 | pub(crate) analysis_host: AnalysisHost, |
76 | pub(crate) diagnostics: DiagnosticCollection, | 72 | pub(crate) diagnostics: DiagnosticCollection, |
77 | pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>, | 73 | pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>, |
78 | pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>, | 74 | pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>, |
79 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | ||
80 | pub(crate) shutdown_requested: bool, | 75 | pub(crate) shutdown_requested: bool, |
81 | pub(crate) status: Status, | 76 | pub(crate) status: Status, |
82 | pub(crate) source_root_config: SourceRootConfig, | 77 | pub(crate) source_root_config: SourceRootConfig, |
83 | pub(crate) proc_macro_client: Option<ProcMacroClient>, | 78 | pub(crate) proc_macro_client: Option<ProcMacroClient>, |
84 | 79 | ||
80 | pub(crate) flycheck: Vec<FlycheckHandle>, | ||
81 | pub(crate) flycheck_sender: Sender<flycheck::Message>, | ||
82 | pub(crate) flycheck_receiver: Receiver<flycheck::Message>, | ||
83 | |||
84 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | ||
85 | pub(crate) vfs_config_version: u32, | ||
86 | pub(crate) vfs_progress_n_total: usize, | ||
87 | pub(crate) vfs_progress_n_done: usize, | ||
88 | |||
85 | /// For both `workspaces` and `workspace_build_data`, the field stores the | 89 | /// For both `workspaces` and `workspace_build_data`, the field stores the |
86 | /// data we actually use, while the `OpQueue` stores the result of the last | 90 | /// data we actually use, while the `OpQueue` stores the result of the last |
87 | /// fetch. | 91 | /// fetch. |
@@ -129,23 +133,27 @@ impl GlobalState { | |||
129 | GlobalState { | 133 | GlobalState { |
130 | sender, | 134 | sender, |
131 | req_queue: ReqQueue::default(), | 135 | req_queue: ReqQueue::default(), |
132 | vfs_config_version: 0, | ||
133 | task_pool, | 136 | task_pool, |
134 | loader, | 137 | loader, |
135 | flycheck: Vec::new(), | ||
136 | flycheck_sender, | ||
137 | flycheck_receiver, | ||
138 | config: Arc::new(config), | 138 | config: Arc::new(config), |
139 | analysis_host, | 139 | analysis_host, |
140 | diagnostics: Default::default(), | 140 | diagnostics: Default::default(), |
141 | mem_docs: FxHashMap::default(), | 141 | mem_docs: FxHashMap::default(), |
142 | semantic_tokens_cache: Arc::new(Default::default()), | 142 | semantic_tokens_cache: Arc::new(Default::default()), |
143 | vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), | ||
144 | shutdown_requested: false, | 143 | shutdown_requested: false, |
145 | status: Status::default(), | 144 | status: Status::default(), |
146 | source_root_config: SourceRootConfig::default(), | 145 | source_root_config: SourceRootConfig::default(), |
147 | proc_macro_client: None, | 146 | proc_macro_client: None, |
148 | 147 | ||
148 | flycheck: Vec::new(), | ||
149 | flycheck_sender, | ||
150 | flycheck_receiver, | ||
151 | |||
152 | vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), | ||
153 | vfs_config_version: 0, | ||
154 | vfs_progress_n_total: 0, | ||
155 | vfs_progress_n_done: 0, | ||
156 | |||
149 | workspaces: Arc::new(Vec::new()), | 157 | workspaces: Arc::new(Vec::new()), |
150 | fetch_workspaces_queue: OpQueue::default(), | 158 | fetch_workspaces_queue: OpQueue::default(), |
151 | workspace_build_data: None, | 159 | 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 { | |||
314 | } | 314 | } |
315 | } | 315 | } |
316 | vfs::loader::Message::Progress { n_total, n_done, config_version } => { | 316 | vfs::loader::Message::Progress { n_total, n_done, config_version } => { |
317 | self.vfs_progress_n_total = n_total; | ||
318 | self.vfs_progress_n_done = n_done; | ||
317 | always!(config_version <= self.vfs_config_version); | 319 | always!(config_version <= self.vfs_config_version); |
318 | if n_total == 0 { | 320 | let state = if n_done == 0 { |
319 | new_status = Status::Invalid; | 321 | Progress::Begin |
322 | } else if n_done < n_total { | ||
323 | Progress::Report | ||
320 | } else { | 324 | } else { |
321 | let state = if n_done == 0 { | 325 | assert_eq!(n_done, n_total); |
322 | new_status = Status::Loading; | 326 | Progress::End |
323 | Progress::Begin | 327 | }; |
324 | } else if n_done < n_total { | 328 | self.report_progress( |
325 | Progress::Report | 329 | "roots scanned", |
326 | } else { | 330 | state, |
327 | assert_eq!(n_done, n_total); | 331 | Some(format!("{}/{}", n_done, n_total)), |
328 | new_status = Status::Ready { | 332 | Some(Progress::fraction(n_done, n_total)), |
329 | partial: self.config.run_build_scripts() | 333 | ) |
330 | && self.workspace_build_data.is_none() | ||
331 | || config_version < self.vfs_config_version, | ||
332 | }; | ||
333 | Progress::End | ||
334 | }; | ||
335 | self.report_progress( | ||
336 | "roots scanned", | ||
337 | state, | ||
338 | Some(format!("{}/{}", n_done, n_total)), | ||
339 | Some(Progress::fraction(n_done, n_total)), | ||
340 | ) | ||
341 | } | ||
342 | } | 334 | } |
343 | } | 335 | } |
344 | // Coalesce many VFS event into a single loop turn | 336 | // Coalesce many VFS event into a single loop turn |
@@ -497,8 +489,9 @@ impl GlobalState { | |||
497 | 489 | ||
498 | RequestDispatcher { req: Some(req), global_state: self } | 490 | RequestDispatcher { req: Some(req), global_state: self } |
499 | .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| { | 491 | .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| { |
500 | self.fetch_workspaces_request(); | 492 | s.fetch_workspaces_request(); |
501 | self.fetch_workspaces_if_needed(); | 493 | s.fetch_workspaces_if_needed(); |
494 | Ok(()) | ||
502 | })? | 495 | })? |
503 | .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? | 496 | .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? |
504 | .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? | 497 | .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? |