aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2021-01-28 15:33:02 +0000
committerEdwin Cheng <[email protected]>2021-01-28 17:04:14 +0000
commit9358eecc042d8b551f58d2d5ddb9c88d258880c1 (patch)
tree7188b0e27d9d00640b5c76319ee59b2d5cab1b05 /crates/rust-analyzer/src/main_loop.rs
parentf421ee672253499b8ca8d1badf98db42525a5216 (diff)
Async Loading outdir and proc-macro
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs38
1 files changed, 33 insertions, 5 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 6d2475a59..f4fd1ac13 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -21,7 +21,7 @@ use crate::{
21 global_state::{file_id_to_url, url_to_file_id, GlobalState, Status}, 21 global_state::{file_id_to_url, url_to_file_id, GlobalState, Status},
22 handlers, lsp_ext, 22 handlers, lsp_ext,
23 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress}, 23 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress},
24 reload::ProjectWorkspaceProgress, 24 reload::{BuildDataProgress, ProjectWorkspaceProgress},
25 Result, 25 Result,
26}; 26};
27 27
@@ -63,6 +63,7 @@ pub(crate) enum Task {
63 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>), 63 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
64 PrimeCaches(PrimeCachesProgress), 64 PrimeCaches(PrimeCachesProgress),
65 FetchWorkspace(ProjectWorkspaceProgress), 65 FetchWorkspace(ProjectWorkspaceProgress),
66 FetchBuildData(BuildDataProgress),
66} 67}
67 68
68impl fmt::Debug for Event { 69impl fmt::Debug for Event {
@@ -226,12 +227,33 @@ impl GlobalState {
226 } 227 }
227 ProjectWorkspaceProgress::End(workspaces) => { 228 ProjectWorkspaceProgress::End(workspaces) => {
228 self.fetch_workspaces_completed(); 229 self.fetch_workspaces_completed();
229 self.switch_workspaces(workspaces); 230 self.switch_workspaces(workspaces, None);
230 (Progress::End, None) 231 (Progress::End, None)
231 } 232 }
232 }; 233 };
233 self.report_progress("fetching", state, msg, None); 234 self.report_progress("fetching", state, msg, None);
234 } 235 }
236 Task::FetchBuildData(progress) => {
237 let (state, msg) = match progress {
238 BuildDataProgress::Begin => (Some(Progress::Begin), None),
239 BuildDataProgress::Report(msg) => {
240 (Some(Progress::Report), Some(msg))
241 }
242 BuildDataProgress::End(collector) => {
243 self.fetch_build_data_completed();
244 let workspaces = (*self.workspaces)
245 .clone()
246 .into_iter()
247 .map(|it| Ok(it))
248 .collect();
249 self.switch_workspaces(workspaces, Some(collector));
250 (Some(Progress::End), None)
251 }
252 };
253 if let Some(state) = state {
254 self.report_progress("loading", state, msg, None);
255 }
256 }
235 } 257 }
236 // Coalesce multiple task events into one loop turn 258 // Coalesce multiple task events into one loop turn
237 task = match self.task_pool.receiver.try_recv() { 259 task = match self.task_pool.receiver.try_recv() {
@@ -287,7 +309,11 @@ impl GlobalState {
287 Progress::Report 309 Progress::Report
288 } else { 310 } else {
289 assert_eq!(n_done, n_total); 311 assert_eq!(n_done, n_total);
290 self.transition(Status::Ready); 312 let status = Status::Ready {
313 partial: self.config.load_out_dirs_from_check()
314 && self.workspace_build_data.is_none(),
315 };
316 self.transition(status);
291 Progress::End 317 Progress::End
292 }; 318 };
293 self.report_progress( 319 self.report_progress(
@@ -372,13 +398,14 @@ impl GlobalState {
372 } 398 }
373 399
374 let state_changed = self.process_changes(); 400 let state_changed = self.process_changes();
375 if prev_status == Status::Loading && self.status == Status::Ready { 401 let is_ready = matches!(self.status, Status::Ready { .. } );
402 if prev_status == Status::Loading && is_ready {
376 for flycheck in &self.flycheck { 403 for flycheck in &self.flycheck {
377 flycheck.update(); 404 flycheck.update();
378 } 405 }
379 } 406 }
380 407
381 if self.status == Status::Ready && (state_changed || prev_status == Status::Loading) { 408 if is_ready && (state_changed || prev_status == Status::Loading) {
382 self.update_file_notifications_on_threadpool(); 409 self.update_file_notifications_on_threadpool();
383 410
384 // Refresh semantic tokens if the client supports it. 411 // Refresh semantic tokens if the client supports it.
@@ -408,6 +435,7 @@ impl GlobalState {
408 } 435 }
409 436
410 self.fetch_workspaces_if_needed(); 437 self.fetch_workspaces_if_needed();
438 self.fetch_build_data_if_needed();
411 439
412 let loop_duration = loop_start.elapsed(); 440 let loop_duration = loop_start.elapsed();
413 if loop_duration > Duration::from_millis(100) { 441 if loop_duration > Duration::from_millis(100) {