aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-02 19:45:00 +0100
committerAleksey Kladov <[email protected]>2021-05-02 19:45:00 +0100
commitcd69307aeeaa6996e782359f503666e5d7b64a25 (patch)
tree044a0acfd1eea1fab1de57b38b020d456264fca4 /crates/rust-analyzer/src/main_loop.rs
parent548c18c062a9372b00b0ad0ad87bef26a6d9e82c (diff)
fix: don't duplicate Progerss::Finised for cache priming
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop.rs30
1 files changed, 10 insertions, 20 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index a3e974e92..ce7ece559 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -8,8 +8,7 @@ use std::{
8 8
9use always_assert::always; 9use always_assert::always;
10use crossbeam_channel::{select, Receiver}; 10use crossbeam_channel::{select, Receiver};
11use ide::PrimeCachesProgress; 11use ide::{FileId, PrimeCachesProgress};
12use ide::{Canceled, FileId};
13use ide_db::base_db::VfsPath; 12use ide_db::base_db::VfsPath;
14use lsp_server::{Connection, Notification, Request, Response}; 13use lsp_server::{Connection, Notification, Request, Response};
15use lsp_types::notification::Notification as _; 14use lsp_types::notification::Notification as _;
@@ -278,8 +277,6 @@ impl GlobalState {
278 }; 277 };
279 } 278 }
280 279
281 let mut finished = false;
282
283 for progress in prime_caches_progress { 280 for progress in prime_caches_progress {
284 let (state, message, fraction); 281 let (state, message, fraction);
285 match progress { 282 match progress {
@@ -297,18 +294,13 @@ impl GlobalState {
297 state = Progress::End; 294 state = Progress::End;
298 message = None; 295 message = None;
299 fraction = 1.0; 296 fraction = 1.0;
300 finished = true; 297
298 self.prime_caches_queue.op_completed(());
301 } 299 }
302 }; 300 };
303 301
304 self.report_progress("Indexing", state, message, Some(fraction)); 302 self.report_progress("Indexing", state, message, Some(fraction));
305 } 303 }
306
307 // If the task is cancelled we may observe two `PrimeCachesProgress::Finished` so we
308 // have to make sure to only call `op_completed()` once.
309 if finished {
310 self.prime_caches_queue.op_completed(());
311 }
312 } 304 }
313 Event::Vfs(mut task) => { 305 Event::Vfs(mut task) => {
314 let _p = profile::span("GlobalState::handle_event/vfs"); 306 let _p = profile::span("GlobalState::handle_event/vfs");
@@ -730,15 +722,13 @@ impl GlobalState {
730 self.task_pool.handle.spawn_with_sender({ 722 self.task_pool.handle.spawn_with_sender({
731 let snap = self.snapshot(); 723 let snap = self.snapshot();
732 move |sender| { 724 move |sender| {
733 snap.analysis 725 let cb = |progress| {
734 .prime_caches(|progress| { 726 sender.send(Task::PrimeCaches(progress)).unwrap();
735 sender.send(Task::PrimeCaches(progress)).unwrap(); 727 };
736 }) 728 match snap.analysis.prime_caches(cb) {
737 .unwrap_or_else(|_: Canceled| { 729 Ok(()) => (),
738 // Pretend that we're done, so that the progress bar is removed. Otherwise 730 Err(_canceled) => (),
739 // the editor may complain about it already existing. 731 }
740 sender.send(Task::PrimeCaches(PrimeCachesProgress::Finished)).unwrap()
741 });
742 } 732 }
743 }); 733 });
744 } 734 }