Skip to content

Commit a319e93

Browse files
bors[bot]matklad
andauthored
Merge #8708
8708: fix: don't duplicate Progerss::Finised for cache priming r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 548c18c + cd69307 commit a319e93

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

crates/ide/src/prime_caches.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress)
2727
let topo = &graph.crates_in_topological_order();
2828

2929
cb(PrimeCachesProgress::Started);
30+
// Take care to emit the finish signal even when the computation is canceled.
3031
let _d = stdx::defer(|| cb(PrimeCachesProgress::Finished));
3132

3233
// FIXME: This would be easy to parallelize, since it's in the ideal ordering for that.

crates/rust-analyzer/src/main_loop.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use std::{
88

99
use always_assert::always;
1010
use crossbeam_channel::{select, Receiver};
11-
use ide::PrimeCachesProgress;
12-
use ide::{Canceled, FileId};
11+
use ide::{FileId, PrimeCachesProgress};
1312
use ide_db::base_db::VfsPath;
1413
use lsp_server::{Connection, Notification, Request, Response};
1514
use lsp_types::notification::Notification as _;
@@ -278,8 +277,6 @@ impl GlobalState {
278277
};
279278
}
280279

281-
let mut finished = false;
282-
283280
for progress in prime_caches_progress {
284281
let (state, message, fraction);
285282
match progress {
@@ -297,18 +294,13 @@ impl GlobalState {
297294
state = Progress::End;
298295
message = None;
299296
fraction = 1.0;
300-
finished = true;
297+
298+
self.prime_caches_queue.op_completed(());
301299
}
302300
};
303301

304302
self.report_progress("Indexing", state, message, Some(fraction));
305303
}
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-
}
312304
}
313305
Event::Vfs(mut task) => {
314306
let _p = profile::span("GlobalState::handle_event/vfs");
@@ -730,15 +722,13 @@ impl GlobalState {
730722
self.task_pool.handle.spawn_with_sender({
731723
let snap = self.snapshot();
732724
move |sender| {
733-
snap.analysis
734-
.prime_caches(|progress| {
735-
sender.send(Task::PrimeCaches(progress)).unwrap();
736-
})
737-
.unwrap_or_else(|_: Canceled| {
738-
// Pretend that we're done, so that the progress bar is removed. Otherwise
739-
// the editor may complain about it already existing.
740-
sender.send(Task::PrimeCaches(PrimeCachesProgress::Finished)).unwrap()
741-
});
725+
let cb = |progress| {
726+
sender.send(Task::PrimeCaches(progress)).unwrap();
727+
};
728+
match snap.analysis.prime_caches(cb) {
729+
Ok(()) => (),
730+
Err(_canceled) => (),
731+
}
742732
}
743733
});
744734
}

0 commit comments

Comments
 (0)