aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/mock.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-24 22:56:13 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-24 22:56:13 +0000
commitc42db0bbd750fae19a91f0a0354240ea6c3bafce (patch)
treebeb7030248280fd8c67eb2b2c9cc4b19c6074c17 /crates/ra_hir/src/mock.rs
parentb308375b82a33687f93468d75c7cc628b83a1351 (diff)
parent31d3a56b1865c33ef54e5d76e606965c87676695 (diff)
Merge #623
623: WIP: module id is not def id r=matklad a=matklad This achieves two things: * makes module_tree & item_map per crate, not per source_root * begins the refactoring to remove universal `DefId` in favor of having separate ids for each kind of `Def`. Currently, only modules get a differnt ID though. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/mock.rs')
-rw-r--r--crates/ra_hir/src/mock.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 4145c8048..361366f6a 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -35,10 +35,6 @@ impl MockDatabase {
35 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);
36 db.query_mut(ra_db::SourceRootQuery) 36 db.query_mut(ra_db::SourceRootQuery)
37 .set(WORKSPACE, Arc::new(source_root.clone())); 37 .set(WORKSPACE, Arc::new(source_root.clone()));
38
39 let mut crate_graph = CrateGraph::default();
40 crate_graph.add_crate_root(file_id);
41 db.set_crate_graph(crate_graph);
42 (db, source_root, file_id) 38 (db, source_root, file_id)
43 } 39 }
44 40
@@ -97,6 +93,8 @@ impl MockDatabase {
97 text: &str, 93 text: &str,
98 ) -> FileId { 94 ) -> FileId {
99 assert!(path.starts_with('/')); 95 assert!(path.starts_with('/'));
96 let is_crate_root = path == "/lib.rs" || path == "/main.rs";
97
100 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 98 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
101 let file_id = FileId(self.file_counter); 99 let file_id = FileId(self.file_counter);
102 self.file_counter += 1; 100 self.file_counter += 1;
@@ -107,6 +105,12 @@ impl MockDatabase {
107 self.query_mut(ra_db::FileSourceRootQuery) 105 self.query_mut(ra_db::FileSourceRootQuery)
108 .set(file_id, source_root_id); 106 .set(file_id, source_root_id);
109 source_root.files.insert(path, file_id); 107 source_root.files.insert(path, file_id);
108
109 if is_crate_root {
110 let mut crate_graph = CrateGraph::default();
111 crate_graph.add_crate_root(file_id);
112 self.set_crate_graph(crate_graph);
113 }
110 file_id 114 file_id
111 } 115 }
112 116
@@ -202,6 +206,7 @@ salsa::database_storage! {
202 fn file_relative_path() for ra_db::FileRelativePathQuery; 206 fn file_relative_path() for ra_db::FileRelativePathQuery;
203 fn file_source_root() for ra_db::FileSourceRootQuery; 207 fn file_source_root() for ra_db::FileSourceRootQuery;
204 fn source_root() for ra_db::SourceRootQuery; 208 fn source_root() for ra_db::SourceRootQuery;
209 fn source_root_crates() for ra_db::SourceRootCratesQuery;
205 fn local_roots() for ra_db::LocalRootsQuery; 210 fn local_roots() for ra_db::LocalRootsQuery;
206 fn library_roots() for ra_db::LibraryRootsQuery; 211 fn library_roots() for ra_db::LibraryRootsQuery;
207 fn crate_graph() for ra_db::CrateGraphQuery; 212 fn crate_graph() for ra_db::CrateGraphQuery;