Skip to content

Commit af50e4f

Browse files
bors[bot]matklad
andauthored
Merge #3474
3474: Prime open files on load r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents ab11c6f + fc970d1 commit af50e4f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

crates/ra_ide/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
pub mod mock_analysis;
1414
mod source_change;
1515

16+
mod prime_caches;
1617
mod status;
1718
mod completion;
1819
mod runnables;
@@ -227,6 +228,10 @@ impl Analysis {
227228
self.with_db(|db| status::status(&*db))
228229
}
229230

231+
pub fn prime_caches(&self, files: Vec<FileId>) -> Cancelable<()> {
232+
self.with_db(|db| prime_caches::prime_caches(db, files))
233+
}
234+
230235
/// Gets the text of the source file.
231236
pub fn file_text(&self, file_id: FileId) -> Cancelable<Arc<String>> {
232237
self.with_db(|db| db.file_text(file_id))

crates/ra_ide/src/prime_caches.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! rust-analyzer is lazy and doesn't not compute anything unless asked. This
2+
//! sometimes is counter productive when, for example, the first goto definition
3+
//! request takes longer to compute. This modules implemented prepopulating of
4+
//! various caches, it's not really advanced at the moment.
5+
6+
use hir::Semantics;
7+
8+
use crate::{FileId, RootDatabase};
9+
10+
pub(crate) fn prime_caches(db: &RootDatabase, files: Vec<FileId>) {
11+
let sema = Semantics::new(db);
12+
for file in files {
13+
let _ = sema.to_module_def(file);
14+
}
15+
}

crates/rust-analyzer/src/main_loop.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ fn loop_turn(
426426
show_message(req::MessageType::Info, msg, &connection.sender);
427427
}
428428
world_state.check_watcher.update();
429+
pool.execute({
430+
let subs = loop_state.subscriptions.subscriptions();
431+
let snap = world_state.snapshot();
432+
move || snap.analysis().prime_caches(subs).unwrap_or_else(|_: Canceled| ())
433+
});
429434
}
430435

431436
if state_changed {

0 commit comments

Comments
 (0)