aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/mock.rs33
-rw-r--r--crates/ra_hir/src/nameres/tests.rs11
2 files changed, 15 insertions, 29 deletions
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};
2 2
3use parking_lot::Mutex; 3use parking_lot::Mutex;
4use ra_db::{ 4use ra_db::{
5 BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, 5 BaseDatabase, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, FilesDatabase,
6 salsa::{self, Database},
7}; 6};
8use relative_path::RelativePathBuf; 7use relative_path::RelativePathBuf;
9use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; 8use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset};
@@ -34,8 +33,7 @@ impl MockDatabase {
34 let mut db = MockDatabase::default(); 33 let mut db = MockDatabase::default();
35 let mut source_root = SourceRoot::default(); 34 let mut source_root = SourceRoot::default();
36 let file_id = db.add_file(WORKSPACE, &mut source_root, "/main.rs", text); 35 let file_id = db.add_file(WORKSPACE, &mut source_root, "/main.rs", text);
37 db.query_mut(ra_db::SourceRootQuery) 36 db.set_source_root(WORKSPACE, Arc::new(source_root.clone()));
38 .set(WORKSPACE, Arc::new(source_root.clone()));
39 (db, source_root, file_id) 37 (db, source_root, file_id)
40 } 38 }
41 39
@@ -45,11 +43,6 @@ impl MockDatabase {
45 (db, position) 43 (db, position)
46 } 44 }
47 45
48 pub(crate) fn set_crate_graph(&mut self, crate_graph: CrateGraph) {
49 self.query_mut(ra_db::CrateGraphQuery)
50 .set((), Arc::new(crate_graph));
51 }
52
53 fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) { 46 fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) {
54 let mut db = MockDatabase::default(); 47 let mut db = MockDatabase::default();
55 48
@@ -81,8 +74,7 @@ impl MockDatabase {
81 self.add_file(source_root_id, &mut source_root, &entry.meta, &entry.text); 74 self.add_file(source_root_id, &mut source_root, &entry.meta, &entry.text);
82 } 75 }
83 } 76 }
84 self.query_mut(ra_db::SourceRootQuery) 77 self.set_source_root(source_root_id, Arc::new(source_root.clone()));
85 .set(source_root_id, Arc::new(source_root.clone()));
86 (source_root, position) 78 (source_root, position)
87 } 79 }
88 80
@@ -100,17 +92,15 @@ impl MockDatabase {
100 let file_id = FileId(self.file_counter); 92 let file_id = FileId(self.file_counter);
101 self.file_counter += 1; 93 self.file_counter += 1;
102 let text = Arc::new(text.to_string()); 94 let text = Arc::new(text.to_string());
103 self.query_mut(ra_db::FileTextQuery).set(file_id, text); 95 self.set_file_text(file_id, text);
104 self.query_mut(ra_db::FileRelativePathQuery) 96 self.set_file_relative_path(file_id, path.clone());
105 .set(file_id, path.clone()); 97 self.set_file_source_root(file_id, source_root_id);
106 self.query_mut(ra_db::FileSourceRootQuery)
107 .set(file_id, source_root_id);
108 source_root.files.insert(path, file_id); 98 source_root.files.insert(path, file_id);
109 99
110 if is_crate_root { 100 if is_crate_root {
111 let mut crate_graph = CrateGraph::default(); 101 let mut crate_graph = CrateGraph::default();
112 crate_graph.add_crate_root(file_id); 102 crate_graph.add_crate_root(file_id);
113 self.set_crate_graph(crate_graph); 103 self.set_crate_graph(Arc::new(crate_graph));
114 } 104 }
115 file_id 105 file_id
116 } 106 }
@@ -149,12 +139,9 @@ impl Default for MockDatabase {
149 interner: Default::default(), 139 interner: Default::default(),
150 file_counter: 0, 140 file_counter: 0,
151 }; 141 };
152 db.query_mut(ra_db::CrateGraphQuery) 142 db.set_crate_graph(Default::default());
153 .set((), Default::default()); 143 db.set_local_roots(Default::default());
154 db.query_mut(ra_db::LocalRootsQuery) 144 db.set_library_roots(Default::default());
155 .set((), Default::default());
156 db.query_mut(ra_db::LibraryRootsQuery)
157 .set((), Default::default());
158 db 145 db
159 } 146 }
160} 147}
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 @@
1use std::sync::Arc; 1use std::sync::Arc;
2 2
3use ra_db::{CrateGraph, SourceRootId, salsa::Database}; 3use ra_db::{CrateGraph, SourceRootId, FilesDatabase};
4use relative_path::RelativePath; 4use relative_path::RelativePath;
5use test_utils::{assert_eq_text, covers}; 5use test_utils::{assert_eq_text, covers};
6 6
@@ -257,7 +257,7 @@ fn item_map_across_crates() {
257 .add_dep(main_crate, "test_crate".into(), lib_crate) 257 .add_dep(main_crate, "test_crate".into(), lib_crate)
258 .unwrap(); 258 .unwrap();
259 259
260 db.set_crate_graph(crate_graph); 260 db.set_crate_graph(Arc::new(crate_graph));
261 261
262 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); 262 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
263 let krate = module.krate(&db).unwrap(); 263 let krate = module.krate(&db).unwrap();
@@ -309,7 +309,7 @@ fn import_across_source_roots() {
309 .add_dep(main_crate, "test_crate".into(), lib_crate) 309 .add_dep(main_crate, "test_crate".into(), lib_crate)
310 .unwrap(); 310 .unwrap();
311 311
312 db.set_crate_graph(crate_graph); 312 db.set_crate_graph(Arc::new(crate_graph));
313 313
314 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); 314 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
315 let krate = module.krate(&db).unwrap(); 315 let krate = module.krate(&db).unwrap();
@@ -351,7 +351,7 @@ fn reexport_across_crates() {
351 .add_dep(main_crate, "test_crate".into(), lib_crate) 351 .add_dep(main_crate, "test_crate".into(), lib_crate)
352 .unwrap(); 352 .unwrap();
353 353
354 db.set_crate_graph(crate_graph); 354 db.set_crate_graph(Arc::new(crate_graph));
355 355
356 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); 356 let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap();
357 let krate = module.krate(&db).unwrap(); 357 let krate = module.krate(&db).unwrap();
@@ -377,8 +377,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) {
377 }); 377 });
378 assert!(format!("{:?}", events).contains("item_map")) 378 assert!(format!("{:?}", events).contains("item_map"))
379 } 379 }
380 db.query_mut(ra_db::FileTextQuery) 380 db.set_file_text(pos.file_id, Arc::new(file_change.to_string()));
381 .set(pos.file_id, Arc::new(file_change.to_string()));
382 381
383 { 382 {
384 let events = db.log_executed(|| { 383 let events = db.log_executed(|| {