aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/mock.rs33
-rw-r--r--crates/ra_hir/src/nameres/tests.rs11
-rw-r--r--crates/ra_ide_api/src/imp.rs39
3 files changed, 29 insertions, 54 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(|| {
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index ddd9354ec..8ecb8b17c 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -5,7 +5,7 @@ use hir::{
5}; 5};
6use ra_db::{ 6use ra_db::{
7 FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase, 7 FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase,
8 salsa::{self, Database}, 8 salsa::Database,
9}; 9};
10use ra_ide_api_light::{self, assists, LocalEdit, Severity}; 10use ra_ide_api_light::{self, assists, LocalEdit, Severity};
11use ra_syntax::{ 11use ra_syntax::{
@@ -18,7 +18,7 @@ use crate::{
18 AnalysisChange, 18 AnalysisChange,
19 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, 19 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
20 Query, RootChange, SourceChange, SourceFileEdit, 20 Query, RootChange, SourceChange, SourceFileEdit,
21 symbol_index::{FileSymbol, LibrarySymbolsQuery}, 21 symbol_index::{FileSymbol, SymbolsDatabase},
22}; 22};
23 23
24impl db::RootDatabase { 24impl db::RootDatabase {
@@ -28,59 +28,48 @@ impl db::RootDatabase {
28 if !change.new_roots.is_empty() { 28 if !change.new_roots.is_empty() {
29 let mut local_roots = Vec::clone(&self.local_roots()); 29 let mut local_roots = Vec::clone(&self.local_roots());
30 for (root_id, is_local) in change.new_roots { 30 for (root_id, is_local) in change.new_roots {
31 self.query_mut(ra_db::SourceRootQuery) 31 self.set_source_root(root_id, Default::default());
32 .set(root_id, Default::default());
33 if is_local { 32 if is_local {
34 local_roots.push(root_id); 33 local_roots.push(root_id);
35 } 34 }
36 } 35 }
37 self.query_mut(ra_db::LocalRootsQuery) 36 self.set_local_roots(Arc::new(local_roots));
38 .set((), Arc::new(local_roots));
39 } 37 }
40 38
41 for (root_id, root_change) in change.roots_changed { 39 for (root_id, root_change) in change.roots_changed {
42 self.apply_root_change(root_id, root_change); 40 self.apply_root_change(root_id, root_change);
43 } 41 }
44 for (file_id, text) in change.files_changed { 42 for (file_id, text) in change.files_changed {
45 self.query_mut(ra_db::FileTextQuery).set(file_id, text) 43 self.set_file_text(file_id, text)
46 } 44 }
47 if !change.libraries_added.is_empty() { 45 if !change.libraries_added.is_empty() {
48 let mut libraries = Vec::clone(&self.library_roots()); 46 let mut libraries = Vec::clone(&self.library_roots());
49 for library in change.libraries_added { 47 for library in change.libraries_added {
50 libraries.push(library.root_id); 48 libraries.push(library.root_id);
51 self.query_mut(ra_db::SourceRootQuery) 49 self.set_source_root(library.root_id, Default::default());
52 .set(library.root_id, Default::default()); 50 self.set_constant_library_symbols(library.root_id, Arc::new(library.symbol_index));
53 self.query_mut(LibrarySymbolsQuery)
54 .set_constant(library.root_id, Arc::new(library.symbol_index));
55 self.apply_root_change(library.root_id, library.root_change); 51 self.apply_root_change(library.root_id, library.root_change);
56 } 52 }
57 self.query_mut(ra_db::LibraryRootsQuery) 53 self.set_library_roots(Arc::new(libraries));
58 .set((), Arc::new(libraries));
59 } 54 }
60 if let Some(crate_graph) = change.crate_graph { 55 if let Some(crate_graph) = change.crate_graph {
61 self.query_mut(ra_db::CrateGraphQuery) 56 self.set_crate_graph(Arc::new(crate_graph))
62 .set((), Arc::new(crate_graph))
63 } 57 }
64 } 58 }
65 59
66 fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) { 60 fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
67 let mut source_root = SourceRoot::clone(&self.source_root(root_id)); 61 let mut source_root = SourceRoot::clone(&self.source_root(root_id));
68 for add_file in root_change.added { 62 for add_file in root_change.added {
69 self.query_mut(ra_db::FileTextQuery) 63 self.set_file_text(add_file.file_id, add_file.text);
70 .set(add_file.file_id, add_file.text); 64 self.set_file_relative_path(add_file.file_id, add_file.path.clone());
71 self.query_mut(ra_db::FileRelativePathQuery) 65 self.set_file_source_root(add_file.file_id, root_id);
72 .set(add_file.file_id, add_file.path.clone());
73 self.query_mut(ra_db::FileSourceRootQuery)
74 .set(add_file.file_id, root_id);
75 source_root.files.insert(add_file.path, add_file.file_id); 66 source_root.files.insert(add_file.path, add_file.file_id);
76 } 67 }
77 for remove_file in root_change.removed { 68 for remove_file in root_change.removed {
78 self.query_mut(ra_db::FileTextQuery) 69 self.set_file_text(remove_file.file_id, Default::default());
79 .set(remove_file.file_id, Default::default());
80 source_root.files.remove(&remove_file.path); 70 source_root.files.remove(&remove_file.path);
81 } 71 }
82 self.query_mut(ra_db::SourceRootQuery) 72 self.set_source_root(root_id, Arc::new(source_root));
83 .set(root_id, Arc::new(source_root));
84 } 73 }
85 74
86 #[allow(unused)] 75 #[allow(unused)]