639: Update salsa r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-01-25 12:34:10 +00:00
commit 021e691997
11 changed files with 108 additions and 212 deletions

14
Cargo.lock generated
View File

@ -726,7 +726,7 @@ dependencies = [
"ra_syntax 0.1.0",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0",
]
@ -746,6 +746,7 @@ dependencies = [
"ra_syntax 0.1.0",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0",
]
@ -766,6 +767,7 @@ dependencies = [
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
"test_utils 0.1.0",
"unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1088,7 +1090,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "salsa"
version = "0.10.0-alpha1"
version = "0.10.0-alpha3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1097,13 +1099,13 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa-macros 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)",
"salsa-macros 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "salsa-macros"
version = "0.10.0-alpha1"
version = "0.10.0-alpha3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1694,8 +1696,8 @@ dependencies = [
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
"checksum salsa 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)" = "4cc048429df53bf0720b93cfa5fa8c3fc3dc7dd65ab41b3f754a8870e7b5c834"
"checksum salsa-macros 0.10.0-alpha1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d5a1aeb618da4b1a00d2885d045154ac30deb04109f3ce73c1fd789caba4fb1"
"checksum salsa 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)" = "135c0977b23f8a9dc16744dd5495989110e3763ba5ea41e386741c7f8901e285"
"checksum salsa-macros 0.10.0-alpha3 (registry+https://github.com/rust-lang/crates.io-index)" = "c9c93b5efed7281334c4bed8470b278076d1ccd6a60da59a15cd0d57792afff8"
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"

View File

@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
[dependencies]
relative-path = "0.4.0"
salsa = "0.10.0-alpha1"
salsa = "0.10.0-alpha3"
rustc-hash = "1.0"
parking_lot = "0.7.0"
ra_arena = { path = "../ra_arena" }

View File

@ -5,11 +5,8 @@
/// Note that neither this module, nor any other part of the analyzer's core do
/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how
/// actual IO is done and lowered to input.
use std::sync::Arc;
use relative_path::RelativePathBuf;
use rustc_hash::FxHashMap;
use salsa;
use ra_syntax::SmolStr;
use rustc_hash::FxHashSet;
@ -146,45 +143,6 @@ impl CrateGraph {
}
}
#[salsa::query_group]
pub trait FilesDatabase: salsa::Database {
/// Text of the file.
#[salsa::input]
fn file_text(&self, file_id: FileId) -> Arc<String>;
/// Path to a file, relative to the root of its source root.
#[salsa::input]
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
/// Source root of the file.
#[salsa::input]
fn file_source_root(&self, file_id: FileId) -> SourceRootId;
/// Contents of the source root.
#[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
#[salsa::input]
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
}
fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
let root = db.source_root(id);
let graph = db.crate_graph();
let res = root
.files
.values()
.filter_map(|&it| graph.crate_id_for_crate_root(it))
.collect::<Vec<_>>();
Arc::new(res)
}
#[cfg(test)]
mod tests {
use super::{CrateGraph, FileId, SmolStr};

View File

@ -4,17 +4,18 @@ mod input;
mod loc2id;
pub mod mock;
use std::panic;
use std::{
panic, sync::Arc,
};
use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc};
use relative_path::RelativePathBuf;
pub use ::salsa as salsa;
pub use crate::{
cancellation::Canceled,
input::{
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency,
FileTextQuery, FileSourceRootQuery, SourceRootQuery, SourceRootCratesQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery,
FileRelativePathQuery
FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency,
},
loc2id::LocationIntener,
};
@ -50,16 +51,6 @@ pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe {
}
}
#[salsa::query_group]
pub trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase {
fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
}
fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {
let text = db.file_text(file_id);
SourceFile::parse(&*text)
}
#[derive(Clone, Copy, Debug)]
pub struct FilePosition {
pub file_id: FileId,
@ -71,3 +62,52 @@ pub struct FileRange {
pub file_id: FileId,
pub range: TextRange,
}
#[salsa::query_group]
pub trait FilesDatabase: salsa::Database {
/// Text of the file.
#[salsa::input]
fn file_text(&self, file_id: FileId) -> Arc<String>;
/// Path to a file, relative to the root of its source root.
#[salsa::input]
fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
/// Source root of the file.
#[salsa::input]
fn file_source_root(&self, file_id: FileId) -> SourceRootId;
/// Contents of the source root.
#[salsa::input]
fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
/// The set of "local" (that is, from the current workspace) roots.
/// Files in local roots are assumed to change frequently.
#[salsa::input]
fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The set of roots for crates.io libraries.
/// Files in libraries are assumed to never change.
#[salsa::input]
fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
/// The crate graph.
#[salsa::input]
fn crate_graph(&self) -> Arc<CrateGraph>;
}
fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
let root = db.source_root(id);
let graph = db.crate_graph();
let res = root
.files
.values()
.filter_map(|&it| graph.crate_id_for_crate_root(it))
.collect::<Vec<_>>();
Arc::new(res)
}
#[salsa::query_group]
pub trait SyntaxDatabase: FilesDatabase + BaseDatabase {
fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
}
fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {
let text = db.file_text(file_id);
SourceFile::parse(&*text)
}

View File

@ -12,6 +12,8 @@ rustc-hash = "1.0"
parking_lot = "0.7.0"
ena = "0.11"
join_to_string = "0.1.3"
salsa = "0.10.0-alpha3"
ra_syntax = { path = "../ra_syntax" }
ra_arena = { path = "../ra_arena" }
ra_db = { path = "../ra_db" }

View File

@ -2,8 +2,7 @@ use std::{sync::Arc, panic};
use parking_lot::Mutex;
use ra_db::{
BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId,
salsa::{self, Database},
BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase,
};
use relative_path::RelativePathBuf;
use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
@ -12,6 +11,7 @@ use crate::{db, HirInterner};
pub const WORKSPACE: SourceRootId = SourceRootId(0);
#[salsa::database(ra_db::FilesDatabase, ra_db::SyntaxDatabase, db::HirDatabase)]
#[derive(Debug)]
pub(crate) struct MockDatabase {
events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
@ -33,8 +33,7 @@ impl MockDatabase {
let mut db = MockDatabase::default();
let mut source_root = SourceRoot::default();
let file_id = db.add_file(WORKSPACE, &mut source_root, "/main.rs", text);
db.query_mut(ra_db::SourceRootQuery)
.set(WORKSPACE, Arc::new(source_root.clone()));
db.set_source_root(WORKSPACE, Arc::new(source_root.clone()));
(db, source_root, file_id)
}
@ -44,11 +43,6 @@ impl MockDatabase {
(db, position)
}
pub(crate) fn set_crate_graph(&mut self, crate_graph: CrateGraph) {
self.query_mut(ra_db::CrateGraphQuery)
.set((), Arc::new(crate_graph));
}
fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) {
let mut db = MockDatabase::default();
@ -80,8 +74,7 @@ impl MockDatabase {
self.add_file(source_root_id, &mut source_root, &entry.meta, &entry.text);
}
}
self.query_mut(ra_db::SourceRootQuery)
.set(source_root_id, Arc::new(source_root.clone()));
self.set_source_root(source_root_id, Arc::new(source_root.clone()));
(source_root, position)
}
@ -99,17 +92,15 @@ impl MockDatabase {
let file_id = FileId(self.file_counter);
self.file_counter += 1;
let text = Arc::new(text.to_string());
self.query_mut(ra_db::FileTextQuery).set(file_id, text);
self.query_mut(ra_db::FileRelativePathQuery)
.set(file_id, path.clone());
self.query_mut(ra_db::FileSourceRootQuery)
.set(file_id, source_root_id);
self.set_file_text(file_id, text);
self.set_file_relative_path(file_id, path.clone());
self.set_file_source_root(file_id, source_root_id);
source_root.files.insert(path, file_id);
if is_crate_root {
let mut crate_graph = CrateGraph::default();
crate_graph.add_crate_root(file_id);
self.set_crate_graph(crate_graph);
self.set_crate_graph(Arc::new(crate_graph));
}
file_id
}
@ -148,12 +139,9 @@ impl Default for MockDatabase {
interner: Default::default(),
file_counter: 0,
};
db.query_mut(ra_db::CrateGraphQuery)
.set((), Default::default());
db.query_mut(ra_db::LocalRootsQuery)
.set((), Default::default());
db.query_mut(ra_db::LibraryRootsQuery)
.set((), Default::default());
db.set_crate_graph(Default::default());
db.set_local_roots(Default::default());
db.set_library_roots(Default::default());
db
}
}
@ -181,8 +169,7 @@ impl MockDatabase {
pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event<MockDatabase>> {
*self.events.lock() = Some(Vec::new());
f();
let events = self.events.lock().take().unwrap();
events
self.events.lock().take().unwrap()
}
pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> {
@ -192,51 +179,11 @@ impl MockDatabase {
.filter_map(|e| match e.kind {
// This pretty horrible, but `Debug` is the only way to inspect
// QueryDescriptor at the moment.
salsa::EventKind::WillExecute { descriptor } => Some(format!("{:?}", descriptor)),
salsa::EventKind::WillExecute { database_key } => {
Some(format!("{:?}", database_key))
}
_ => None,
})
.collect()
}
}
salsa::database_storage! {
pub(crate) struct MockDatabaseStorage for MockDatabase {
impl ra_db::FilesDatabase {
fn file_text() for ra_db::FileTextQuery;
fn file_relative_path() for ra_db::FileRelativePathQuery;
fn file_source_root() for ra_db::FileSourceRootQuery;
fn source_root() for ra_db::SourceRootQuery;
fn source_root_crates() for ra_db::SourceRootCratesQuery;
fn local_roots() for ra_db::LocalRootsQuery;
fn library_roots() for ra_db::LibraryRootsQuery;
fn crate_graph() for ra_db::CrateGraphQuery;
}
impl ra_db::SyntaxDatabase {
fn source_file() for ra_db::SourceFileQuery;
}
impl db::HirDatabase {
fn hir_source_file() for db::HirSourceFileQuery;
fn expand_macro_invocation() for db::ExpandMacroInvocationQuery;
fn module_tree() for db::ModuleTreeQuery;
fn fn_scopes() for db::FnScopesQuery;
fn file_items() for db::FileItemsQuery;
fn file_item() for db::FileItemQuery;
fn lower_module() for db::LowerModuleQuery;
fn lower_module_module() for db::LowerModuleModuleQuery;
fn lower_module_source_map() for db::LowerModuleSourceMapQuery;
fn item_map() for db::ItemMapQuery;
fn submodules() for db::SubmodulesQuery;
fn infer() for db::InferQuery;
fn type_for_def() for db::TypeForDefQuery;
fn type_for_field() for db::TypeForFieldQuery;
fn struct_data() for db::StructDataQuery;
fn enum_data() for db::EnumDataQuery;
fn impls_in_module() for db::ImplsInModuleQuery;
fn impls_in_crate() for db::ImplsInCrateQuery;
fn body_hir() for db::BodyHirQuery;
fn body_syntax_mapping() for db::BodySyntaxMappingQuery;
fn fn_signature() for db::FnSignatureQuery;
fn generic_params() for db::GenericParamsQuery;
}
}
}

View File

@ -1,6 +1,6 @@
use std::sync::Arc;
use ra_db::{CrateGraph, SourceRootId, salsa::Database};
use ra_db::{CrateGraph, SourceRootId, FilesDatabase};
use relative_path::RelativePath;
use test_utils::{assert_eq_text, covers};
@ -257,7 +257,7 @@ fn item_map_across_crates() {
.add_dep(main_crate, "test_crate".into(), lib_crate)
.unwrap();
db.set_crate_graph(crate_graph);
db.set_crate_graph(Arc::new(crate_graph));
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
let krate = module.krate(&db).unwrap();
@ -309,7 +309,7 @@ fn import_across_source_roots() {
.add_dep(main_crate, "test_crate".into(), lib_crate)
.unwrap();
db.set_crate_graph(crate_graph);
db.set_crate_graph(Arc::new(crate_graph));
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
let krate = module.krate(&db).unwrap();
@ -351,7 +351,7 @@ fn reexport_across_crates() {
.add_dep(main_crate, "test_crate".into(), lib_crate)
.unwrap();
db.set_crate_graph(crate_graph);
db.set_crate_graph(Arc::new(crate_graph));
let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
let krate = module.krate(&db).unwrap();
@ -377,8 +377,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) {
});
assert!(format!("{:?}", events).contains("item_map"))
}
db.query_mut(ra_db::FileTextQuery)
.set(pos.file_id, Arc::new(file_change.to_string()));
db.set_file_text(pos.file_id, Arc::new(file_change.to_string()));
{
let events = db.log_executed(|| {

View File

@ -13,6 +13,7 @@ fst = "0.3.1"
rustc-hash = "1.0"
parking_lot = "0.7.0"
unicase = "2.2.0"
salsa = "0.10.0-alpha3"
ra_syntax = { path = "../ra_syntax" }
ra_ide_api_light = { path = "../ra_ide_api_light" }

View File

@ -7,6 +7,13 @@ use ra_db::{
use crate::{symbol_index, LineIndex};
#[salsa::database(
ra_db::FilesDatabase,
ra_db::SyntaxDatabase,
LineIndexDatabase,
symbol_index::SymbolsDatabase,
hir::db::HirDatabase
)]
#[derive(Debug)]
pub(crate) struct RootDatabase {
runtime: salsa::Runtime<RootDatabase>,
@ -64,52 +71,3 @@ fn line_index(db: &impl ra_db::FilesDatabase, file_id: FileId) -> Arc<LineIndex>
let text = db.file_text(file_id);
Arc::new(LineIndex::new(&*text))
}
salsa::database_storage! {
pub(crate) struct RootDatabaseStorage for RootDatabase {
impl ra_db::FilesDatabase {
fn file_text() for ra_db::FileTextQuery;
fn file_relative_path() for ra_db::FileRelativePathQuery;
fn file_source_root() for ra_db::FileSourceRootQuery;
fn source_root() for ra_db::SourceRootQuery;
fn source_root_crates() for ra_db::SourceRootCratesQuery;
fn local_roots() for ra_db::LocalRootsQuery;
fn library_roots() for ra_db::LibraryRootsQuery;
fn crate_graph() for ra_db::CrateGraphQuery;
}
impl ra_db::SyntaxDatabase {
fn source_file() for ra_db::SourceFileQuery;
}
impl LineIndexDatabase {
fn line_index() for LineIndexQuery;
}
impl symbol_index::SymbolsDatabase {
fn file_symbols() for symbol_index::FileSymbolsQuery;
fn library_symbols() for symbol_index::LibrarySymbolsQuery;
}
impl hir::db::HirDatabase {
fn hir_source_file() for hir::db::HirSourceFileQuery;
fn expand_macro_invocation() for hir::db::ExpandMacroInvocationQuery;
fn module_tree() for hir::db::ModuleTreeQuery;
fn fn_scopes() for hir::db::FnScopesQuery;
fn file_items() for hir::db::FileItemsQuery;
fn file_item() for hir::db::FileItemQuery;
fn lower_module() for hir::db::LowerModuleQuery;
fn lower_module_module() for hir::db::LowerModuleModuleQuery;
fn lower_module_source_map() for hir::db::LowerModuleSourceMapQuery;
fn item_map() for hir::db::ItemMapQuery;
fn submodules() for hir::db::SubmodulesQuery;
fn infer() for hir::db::InferQuery;
fn type_for_def() for hir::db::TypeForDefQuery;
fn type_for_field() for hir::db::TypeForFieldQuery;
fn struct_data() for hir::db::StructDataQuery;
fn enum_data() for hir::db::EnumDataQuery;
fn impls_in_module() for hir::db::ImplsInModuleQuery;
fn impls_in_crate() for hir::db::ImplsInCrateQuery;
fn body_hir() for hir::db::BodyHirQuery;
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
fn fn_signature() for hir::db::FnSignatureQuery;
fn generic_params() for hir::db::GenericParamsQuery;
}
}
}

View File

@ -5,7 +5,7 @@ use hir::{
};
use ra_db::{
FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase,
salsa::{self, Database},
salsa::Database,
};
use ra_ide_api_light::{self, assists, LocalEdit, Severity};
use ra_syntax::{
@ -18,7 +18,7 @@ use crate::{
AnalysisChange,
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
Query, RootChange, SourceChange, SourceFileEdit,
symbol_index::{FileSymbol, LibrarySymbolsQuery},
symbol_index::{FileSymbol, SymbolsDatabase},
};
impl db::RootDatabase {
@ -28,59 +28,48 @@ impl db::RootDatabase {
if !change.new_roots.is_empty() {
let mut local_roots = Vec::clone(&self.local_roots());
for (root_id, is_local) in change.new_roots {
self.query_mut(ra_db::SourceRootQuery)
.set(root_id, Default::default());
self.set_source_root(root_id, Default::default());
if is_local {
local_roots.push(root_id);
}
}
self.query_mut(ra_db::LocalRootsQuery)
.set((), Arc::new(local_roots));
self.set_local_roots(Arc::new(local_roots));
}
for (root_id, root_change) in change.roots_changed {
self.apply_root_change(root_id, root_change);
}
for (file_id, text) in change.files_changed {
self.query_mut(ra_db::FileTextQuery).set(file_id, text)
self.set_file_text(file_id, text)
}
if !change.libraries_added.is_empty() {
let mut libraries = Vec::clone(&self.library_roots());
for library in change.libraries_added {
libraries.push(library.root_id);
self.query_mut(ra_db::SourceRootQuery)
.set(library.root_id, Default::default());
self.query_mut(LibrarySymbolsQuery)
.set_constant(library.root_id, Arc::new(library.symbol_index));
self.set_source_root(library.root_id, Default::default());
self.set_constant_library_symbols(library.root_id, Arc::new(library.symbol_index));
self.apply_root_change(library.root_id, library.root_change);
}
self.query_mut(ra_db::LibraryRootsQuery)
.set((), Arc::new(libraries));
self.set_library_roots(Arc::new(libraries));
}
if let Some(crate_graph) = change.crate_graph {
self.query_mut(ra_db::CrateGraphQuery)
.set((), Arc::new(crate_graph))
self.set_crate_graph(Arc::new(crate_graph))
}
}
fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
let mut source_root = SourceRoot::clone(&self.source_root(root_id));
for add_file in root_change.added {
self.query_mut(ra_db::FileTextQuery)
.set(add_file.file_id, add_file.text);
self.query_mut(ra_db::FileRelativePathQuery)
.set(add_file.file_id, add_file.path.clone());
self.query_mut(ra_db::FileSourceRootQuery)
.set(add_file.file_id, root_id);
self.set_file_text(add_file.file_id, add_file.text);
self.set_file_relative_path(add_file.file_id, add_file.path.clone());
self.set_file_source_root(add_file.file_id, root_id);
source_root.files.insert(add_file.path, add_file.file_id);
}
for remove_file in root_change.removed {
self.query_mut(ra_db::FileTextQuery)
.set(remove_file.file_id, Default::default());
self.set_file_text(remove_file.file_id, Default::default());
source_root.files.remove(&remove_file.path);
}
self.query_mut(ra_db::SourceRootQuery)
.set(root_id, Arc::new(source_root));
self.set_source_root(root_id, Arc::new(source_root));
}
#[allow(unused)]

View File

@ -6,7 +6,7 @@ use ra_db::{
use crate::db::RootDatabase;
pub(crate) fn status(db: &RootDatabase) -> String {
let n_parsed_files = db.query(SourceFileQuery).keys::<Vec<_>>().len();
let n_parsed_files = db.query(SourceFileQuery).entries::<Vec<_>>().len();
let n_defs = {
let interner: &hir::HirInterner = db.as_ref();
interner.len()