From 08c12e424d5d3fb4e11f081a07b9c265dc7a96b6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 15:25:01 +0300 Subject: use set methods --- crates/ra_hir/src/mock.rs | 33 ++++++++++----------------------- crates/ra_hir/src/nameres/tests.rs | 11 +++++------ 2 files changed, 15 insertions(+), 29 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index aa54336b8..36b174cd6 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -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}; @@ -34,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) } @@ -45,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) { let mut db = MockDatabase::default(); @@ -81,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) } @@ -100,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 } @@ -149,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 } } diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index c033bebe8..24936976c 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -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(|| { -- cgit v1.2.3