aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-10-06 16:58:03 +0100
committerJonas Schievink <[email protected]>2020-10-12 12:35:01 +0100
commitcde7392ec809599e6337d91561971e08c8e06831 (patch)
tree061cc24d3af0d5189e5b1722a0f7416cc1a8bc34 /crates/rust-analyzer/src/main_loop.rs
parent518f6d772482c7c58e59081f340947087a9b4800 (diff)
Improve prime_caches and display its progress
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs42
1 files changed, 35 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 06b38d99c..fb18f9014 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -7,6 +7,7 @@ use std::{
7 7
8use base_db::VfsPath; 8use base_db::VfsPath;
9use crossbeam_channel::{select, Receiver}; 9use crossbeam_channel::{select, Receiver};
10use ide::PrimeCachesProgress;
10use ide::{Canceled, FileId}; 11use ide::{Canceled, FileId};
11use lsp_server::{Connection, Notification, Request, Response}; 12use lsp_server::{Connection, Notification, Request, Response};
12use lsp_types::notification::Notification as _; 13use lsp_types::notification::Notification as _;
@@ -61,7 +62,7 @@ pub(crate) enum Task {
61 Response(Response), 62 Response(Response),
62 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>), 63 Diagnostics(Vec<(FileId, Vec<lsp_types::Diagnostic>)>),
63 Workspaces(Vec<anyhow::Result<ProjectWorkspace>>), 64 Workspaces(Vec<anyhow::Result<ProjectWorkspace>>),
64 Unit, 65 PrimeCaches(PrimeCachesProgress),
65} 66}
66 67
67impl fmt::Debug for Event { 68impl fmt::Debug for Event {
@@ -197,7 +198,28 @@ impl GlobalState {
197 } 198 }
198 } 199 }
199 Task::Workspaces(workspaces) => self.switch_workspaces(workspaces), 200 Task::Workspaces(workspaces) => self.switch_workspaces(workspaces),
200 Task::Unit => (), 201 Task::PrimeCaches(progress) => {
202 let (state, message, fraction);
203 match progress {
204 PrimeCachesProgress::Started => {
205 state = Progress::Begin;
206 message = None;
207 fraction = 0.0;
208 }
209 PrimeCachesProgress::StartedOnCrate { on_crate, n_done, n_total } => {
210 state = Progress::Report;
211 message = Some(format!("{}/{} ({})", n_done, n_total, on_crate));
212 fraction = Progress::fraction(n_done, n_total);
213 }
214 PrimeCachesProgress::Finished => {
215 state = Progress::End;
216 message = None;
217 fraction = 1.0;
218 }
219 };
220
221 self.report_progress("indexing", state, message, Some(fraction));
222 }
201 }, 223 },
202 Event::Vfs(mut task) => { 224 Event::Vfs(mut task) => {
203 let _p = profile::span("GlobalState::handle_event/vfs"); 225 let _p = profile::span("GlobalState::handle_event/vfs");
@@ -573,12 +595,18 @@ impl GlobalState {
573 Task::Diagnostics(diagnostics) 595 Task::Diagnostics(diagnostics)
574 }) 596 })
575 } 597 }
576 self.task_pool.handle.spawn({ 598 self.task_pool.handle.spawn_with_sender({
577 let subs = subscriptions;
578 let snap = self.snapshot(); 599 let snap = self.snapshot();
579 move || { 600 move |sender| {
580 snap.analysis.prime_caches(subs).unwrap_or_else(|_: Canceled| ()); 601 snap.analysis
581 Task::Unit 602 .prime_caches(|progress| {
603 sender.send(Task::PrimeCaches(progress)).unwrap();
604 })
605 .unwrap_or_else(|_: Canceled| {
606 // Pretend that we're done, so that the progress bar is removed. Otherwise
607 // the editor may complain about it already existing.
608 sender.send(Task::PrimeCaches(PrimeCachesProgress::Finished)).unwrap()
609 });
582 } 610 }
583 }); 611 });
584 } 612 }