fix: don't duplicate Progerss::Finised for cache priming

This commit is contained in:
Aleksey Kladov 2021-05-02 21:45:00 +03:00
parent 548c18c062
commit cd69307aee
2 changed files with 11 additions and 20 deletions

View file

@ -27,6 +27,7 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress)
let topo = &graph.crates_in_topological_order(); let topo = &graph.crates_in_topological_order();
cb(PrimeCachesProgress::Started); cb(PrimeCachesProgress::Started);
// Take care to emit the finish signal even when the computation is canceled.
let _d = stdx::defer(|| cb(PrimeCachesProgress::Finished)); let _d = stdx::defer(|| cb(PrimeCachesProgress::Finished));
// FIXME: This would be easy to parallelize, since it's in the ideal ordering for that. // FIXME: This would be easy to parallelize, since it's in the ideal ordering for that.

View file

@ -8,8 +8,7 @@ use std::{
use always_assert::always; use always_assert::always;
use crossbeam_channel::{select, Receiver}; use crossbeam_channel::{select, Receiver};
use ide::PrimeCachesProgress; use ide::{FileId, PrimeCachesProgress};
use ide::{Canceled, FileId};
use ide_db::base_db::VfsPath; use ide_db::base_db::VfsPath;
use lsp_server::{Connection, Notification, Request, Response}; use lsp_server::{Connection, Notification, Request, Response};
use lsp_types::notification::Notification as _; use lsp_types::notification::Notification as _;
@ -278,8 +277,6 @@ impl GlobalState {
}; };
} }
let mut finished = false;
for progress in prime_caches_progress { for progress in prime_caches_progress {
let (state, message, fraction); let (state, message, fraction);
match progress { match progress {
@ -297,18 +294,13 @@ impl GlobalState {
state = Progress::End; state = Progress::End;
message = None; message = None;
fraction = 1.0; fraction = 1.0;
finished = true;
self.prime_caches_queue.op_completed(());
} }
}; };
self.report_progress("Indexing", state, message, Some(fraction)); self.report_progress("Indexing", state, message, Some(fraction));
} }
// If the task is cancelled we may observe two `PrimeCachesProgress::Finished` so we
// have to make sure to only call `op_completed()` once.
if finished {
self.prime_caches_queue.op_completed(());
}
} }
Event::Vfs(mut task) => { Event::Vfs(mut task) => {
let _p = profile::span("GlobalState::handle_event/vfs"); let _p = profile::span("GlobalState::handle_event/vfs");
@ -730,15 +722,13 @@ impl GlobalState {
self.task_pool.handle.spawn_with_sender({ self.task_pool.handle.spawn_with_sender({
let snap = self.snapshot(); let snap = self.snapshot();
move |sender| { move |sender| {
snap.analysis let cb = |progress| {
.prime_caches(|progress| {
sender.send(Task::PrimeCaches(progress)).unwrap(); sender.send(Task::PrimeCaches(progress)).unwrap();
}) };
.unwrap_or_else(|_: Canceled| { match snap.analysis.prime_caches(cb) {
// Pretend that we're done, so that the progress bar is removed. Otherwise Ok(()) => (),
// the editor may complain about it already existing. Err(_canceled) => (),
sender.send(Task::PrimeCaches(PrimeCachesProgress::Finished)).unwrap() }
});
} }
}); });
} }