Unnamed repository; edit this file 'description' to name the repository.
Do not unnecessarily re-trigger garbage collection if no inputs have changed
| -rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 8 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 10 |
2 files changed, 14 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 91ea2a343e..9beab3c0e4 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -15,7 +15,7 @@ use hir::ChangeWithProcMacros; use ide::{Analysis, AnalysisHost, Cancellable, FileId, SourceRootId}; use ide_db::{ MiniCore, - base_db::{Crate, ProcMacroPaths, SourceDatabase}, + base_db::{Crate, ProcMacroPaths, SourceDatabase, salsa::Revision}, }; use itertools::Itertools; use load_cargo::SourceRootConfig; @@ -194,12 +194,13 @@ pub(crate) struct GlobalState { pub(crate) incomplete_crate_graph: bool, pub(crate) minicore: MiniCoreRustAnalyzerInternalOnly, + pub(crate) last_gc_revision: Revision, } // FIXME: This should move to the VFS once the rewrite is done. #[derive(Debug, Clone, Default)] pub(crate) struct MiniCoreRustAnalyzerInternalOnly { - pub(crate) minicore_text: Option<String>, + pub(crate) minicore_text: Option<Arc<str>>, } /// An immutable snapshot of the world's state at a point in time. @@ -256,6 +257,8 @@ impl GlobalState { let (discover_sender, discover_receiver) = unbounded(); + let last_gc_revision = analysis_host.raw_database().nonce_and_revision().1; + let mut this = GlobalState { sender, req_queue: ReqQueue::default(), @@ -319,6 +322,7 @@ impl GlobalState { incomplete_crate_graph: false, minicore: MiniCoreRustAnalyzerInternalOnly::default(), + last_gc_revision, }; // Apply any required database inputs from the config. this.update_configuration(config); diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 54cd824a03..dd0813c144 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -536,9 +536,14 @@ impl GlobalState { self.update_tests(); } + let current_revision = self.analysis_host.raw_database().nonce_and_revision().1; // no work is currently being done, now we can block a bit and clean up our garbage - if self.task_pool.handle.is_empty() && self.fmt_pool.handle.is_empty() { + if self.task_pool.handle.is_empty() + && self.fmt_pool.handle.is_empty() + && current_revision != self.last_gc_revision + { self.analysis_host.trigger_garbage_collection(); + self.last_gc_revision = current_revision; } } @@ -912,7 +917,8 @@ impl GlobalState { // Not a lot of bad can happen from mistakenly identifying `minicore`, so proceed with that. self.minicore.minicore_text = contents .as_ref() - .and_then(|contents| String::from_utf8(contents.clone()).ok()); + .and_then(|contents| str::from_utf8(contents).ok()) + .map(triomphe::Arc::from); } let path = VfsPath::from(path); |