diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-05 12:47:39 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-05 12:47:39 +0000 |
commit | af50e4ff062e1b34c8447c119365c91e8f617d8a (patch) | |
tree | 099601eabb046133e31818a98db2e8a5eaeb61c2 | |
parent | ab11c6f08a18ab36c8d09607f8b72c007edde9d4 (diff) | |
parent | fc970d188e9eeca02bc189bbcc0082a0bbf13a57 (diff) |
Merge #3474
3474: Prime open files on load r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_ide/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/prime_caches.rs | 15 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 5 |
3 files changed, 25 insertions, 0 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 5a41f702e..4dfe0553e 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -13,6 +13,7 @@ | |||
13 | pub mod mock_analysis; | 13 | pub mod mock_analysis; |
14 | mod source_change; | 14 | mod source_change; |
15 | 15 | ||
16 | mod prime_caches; | ||
16 | mod status; | 17 | mod status; |
17 | mod completion; | 18 | mod completion; |
18 | mod runnables; | 19 | mod runnables; |
@@ -227,6 +228,10 @@ impl Analysis { | |||
227 | self.with_db(|db| status::status(&*db)) | 228 | self.with_db(|db| status::status(&*db)) |
228 | } | 229 | } |
229 | 230 | ||
231 | pub fn prime_caches(&self, files: Vec<FileId>) -> Cancelable<()> { | ||
232 | self.with_db(|db| prime_caches::prime_caches(db, files)) | ||
233 | } | ||
234 | |||
230 | /// Gets the text of the source file. | 235 | /// Gets the text of the source file. |
231 | pub fn file_text(&self, file_id: FileId) -> Cancelable<Arc<String>> { | 236 | pub fn file_text(&self, file_id: FileId) -> Cancelable<Arc<String>> { |
232 | self.with_db(|db| db.file_text(file_id)) | 237 | self.with_db(|db| db.file_text(file_id)) |
diff --git a/crates/ra_ide/src/prime_caches.rs b/crates/ra_ide/src/prime_caches.rs new file mode 100644 index 000000000..628c989bf --- /dev/null +++ b/crates/ra_ide/src/prime_caches.rs | |||
@@ -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 | } | ||
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index fe804aada..580ad1f2c 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -426,6 +426,11 @@ fn loop_turn( | |||
426 | show_message(req::MessageType::Info, msg, &connection.sender); | 426 | show_message(req::MessageType::Info, msg, &connection.sender); |
427 | } | 427 | } |
428 | world_state.check_watcher.update(); | 428 | 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 | }); | ||
429 | } | 434 | } |
430 | 435 | ||
431 | if state_changed { | 436 | if state_changed { |