diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-28 17:43:51 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-28 17:43:51 +0000 |
commit | 703e6bfdb6d7db87318a8f7c3b5c8c96283ee379 (patch) | |
tree | 479c972997987d535c84d8cb03ab0c05d935a280 /crates/rust-analyzer/src/main_loop.rs | |
parent | 00b9b2d6458d20e15e602e659cafe6c09765c5ae (diff) | |
parent | d069ef60b6d46925bebbb7bb0b59953ef38153a2 (diff) |
Merge #7412
7412: Async loading for outdir and proc-macro r=maklad a=edwin0cheng
cc #7328

[Edit]
~~Finding a way to know when the workspace and build data are loaded...~~
[Edit 2]
Not perfect solution, but seem to work now.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 38 |
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 | ||
68 | impl fmt::Debug for Event { | 69 | impl 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) { |