2019-01-26 11:33:33 -06:00
|
|
|
use std::{
|
|
|
|
sync::Arc,
|
|
|
|
time,
|
|
|
|
};
|
2019-01-08 13:33:36 -06:00
|
|
|
|
2019-01-17 05:11:00 -06:00
|
|
|
use ra_db::{
|
2019-01-26 02:20:30 -06:00
|
|
|
CheckCanceled, FileId, Canceled, SourceDatabase,
|
2019-06-07 01:50:32 -05:00
|
|
|
salsa::{self, Database},
|
2019-01-17 05:11:00 -06:00
|
|
|
};
|
2019-01-08 13:33:36 -06:00
|
|
|
|
2019-01-26 02:17:05 -06:00
|
|
|
use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}};
|
2019-01-08 13:33:36 -06:00
|
|
|
|
2019-01-25 06:16:50 -06:00
|
|
|
#[salsa::database(
|
2019-01-26 02:20:30 -06:00
|
|
|
ra_db::SourceDatabaseStorage,
|
2019-01-25 14:27:16 -06:00
|
|
|
LineIndexDatabaseStorage,
|
|
|
|
symbol_index::SymbolsDatabaseStorage,
|
2019-06-01 13:17:57 -05:00
|
|
|
hir::db::AstDatabaseStorage,
|
|
|
|
hir::db::DefDatabaseStorage,
|
|
|
|
hir::db::HirDatabaseStorage
|
2019-01-25 06:16:50 -06:00
|
|
|
)]
|
2019-01-08 13:33:36 -06:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) struct RootDatabase {
|
|
|
|
runtime: salsa::Runtime<RootDatabase>,
|
2019-01-26 11:33:33 -06:00
|
|
|
pub(crate) last_gc: time::Instant,
|
|
|
|
pub(crate) last_gc_check: time::Instant,
|
2019-01-08 13:33:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl salsa::Database for RootDatabase {
|
|
|
|
fn salsa_runtime(&self) -> &salsa::Runtime<RootDatabase> {
|
|
|
|
&self.runtime
|
|
|
|
}
|
2019-01-10 03:20:32 -06:00
|
|
|
fn on_propagated_panic(&self) -> ! {
|
|
|
|
Canceled::throw()
|
|
|
|
}
|
cancel salsa's validation
This small fix should improve rust-analyzer resopnsivness for
real-time operations like onEnter handling.
Turns out, salsa's validation can take hundreds of milliseconds, and,
in case no changes were made, it won't be triggering any queries.
Because we check for cancellation in queries, that means that
validation is not cancellable!
What this PR does is injecting check_canceled checks into validation,
by using salsa's event API, which wasn't meant to be used like this,
but, hey, it works!
Here's the onEnter handling before and after this change:
https://youtu.be/7-ffPzgvH7o
2019-05-30 01:51:25 -05:00
|
|
|
fn salsa_event(&self, event: impl Fn() -> salsa::Event<RootDatabase>) {
|
2019-06-12 10:05:02 -05:00
|
|
|
match event().kind {
|
|
|
|
salsa::EventKind::DidValidateMemoizedValue { .. }
|
|
|
|
| salsa::EventKind::WillExecute { .. } => {
|
|
|
|
self.check_canceled();
|
|
|
|
}
|
|
|
|
_ => (),
|
cancel salsa's validation
This small fix should improve rust-analyzer resopnsivness for
real-time operations like onEnter handling.
Turns out, salsa's validation can take hundreds of milliseconds, and,
in case no changes were made, it won't be triggering any queries.
Because we check for cancellation in queries, that means that
validation is not cancellable!
What this PR does is injecting check_canceled checks into validation,
by using salsa's event API, which wasn't meant to be used like this,
but, hey, it works!
Here's the onEnter handling before and after this change:
https://youtu.be/7-ffPzgvH7o
2019-05-30 01:51:25 -05:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 13:33:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RootDatabase {
|
|
|
|
fn default() -> RootDatabase {
|
2019-06-07 12:49:29 -05:00
|
|
|
RootDatabase::new(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RootDatabase {
|
|
|
|
pub fn new(lru_capacity: Option<usize>) -> RootDatabase {
|
2019-01-08 13:33:36 -06:00
|
|
|
let mut db = RootDatabase {
|
|
|
|
runtime: salsa::Runtime::default(),
|
2019-01-26 11:33:33 -06:00
|
|
|
last_gc: time::Instant::now(),
|
|
|
|
last_gc_check: time::Instant::now(),
|
2019-01-08 13:33:36 -06:00
|
|
|
};
|
2019-01-26 02:17:05 -06:00
|
|
|
db.set_crate_graph(Default::default());
|
|
|
|
db.set_local_roots(Default::default());
|
|
|
|
db.set_library_roots(Default::default());
|
2019-06-07 12:49:29 -05:00
|
|
|
let lru_capacity = lru_capacity.unwrap_or(ra_db::DEFAULT_LRU_CAP);
|
|
|
|
db.query_mut(ra_db::ParseQuery).set_lru_capacity(lru_capacity);
|
|
|
|
db.query_mut(hir::db::ParseMacroQuery).set_lru_capacity(lru_capacity);
|
2019-01-08 13:33:36 -06:00
|
|
|
db
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl salsa::ParallelDatabase for RootDatabase {
|
|
|
|
fn snapshot(&self) -> salsa::Snapshot<RootDatabase> {
|
|
|
|
salsa::Snapshot::new(RootDatabase {
|
|
|
|
runtime: self.runtime.snapshot(self),
|
2019-01-26 11:33:33 -06:00
|
|
|
last_gc: self.last_gc.clone(),
|
|
|
|
last_gc_check: self.last_gc_check.clone(),
|
2019-01-08 13:33:36 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:27:16 -06:00
|
|
|
#[salsa::query_group(LineIndexDatabaseStorage)]
|
2019-01-26 02:20:30 -06:00
|
|
|
pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled {
|
2019-01-17 05:11:00 -06:00
|
|
|
fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
|
2019-01-08 13:33:36 -06:00
|
|
|
}
|
|
|
|
|
2019-01-26 02:20:30 -06:00
|
|
|
fn line_index(db: &impl ra_db::SourceDatabase, file_id: FileId) -> Arc<LineIndex> {
|
2019-01-08 13:33:36 -06:00
|
|
|
let text = db.file_text(file_id);
|
|
|
|
Arc::new(LineIndex::new(&*text))
|
|
|
|
}
|