aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErlend Tobiassen <[email protected]>2019-01-27 15:32:31 +0000
committerErlend Tobiassen <[email protected]>2019-01-27 15:32:31 +0000
commitb775fa285c985821f38f09c25507d80ee793ecfd (patch)
treefc215f17910db6265072bb3b81a29ac034d53a14
parentb149882d198818d6302c2a6318d68c4e0b4380ff (diff)
Revert parts of "Test non standard crate root"
Prefer cursor position over file_map
-rw-r--r--crates/ra_hir/src/mock.rs16
-rw-r--r--crates/ra_hir/src/nameres/tests.rs8
2 files changed, 9 insertions, 15 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 2bba11e42..7da15eca0 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 mock::FileMap, CheckCanceled, CrateGraph, FileId, FilePosition, SourceDatabase, 5 CheckCanceled, FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa,
6 SourceRoot, SourceRootId, salsa
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};
@@ -18,7 +17,7 @@ pub(crate) struct MockDatabase {
18 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 17 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
19 runtime: salsa::Runtime<MockDatabase>, 18 runtime: salsa::Runtime<MockDatabase>,
20 interner: Arc<HirInterner>, 19 interner: Arc<HirInterner>,
21 file_map: Arc<FileMap>, 20 file_counter: u32,
22} 21}
23 22
24impl panic::RefUnwindSafe for MockDatabase {} 23impl panic::RefUnwindSafe for MockDatabase {}
@@ -44,10 +43,6 @@ impl MockDatabase {
44 (db, position) 43 (db, position)
45 } 44 }
46 45
47 pub(crate) fn file_id(&self, file: &str) -> FileId {
48 self.file_map.file_id(file)
49 }
50
51 fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) { 46 fn from_fixture(fixture: &str) -> (MockDatabase, SourceRoot, Option<FilePosition>) {
52 let mut db = MockDatabase::default(); 47 let mut db = MockDatabase::default();
53 48
@@ -94,7 +89,8 @@ impl MockDatabase {
94 let is_crate_root = path == "/lib.rs" || path == "/main.rs"; 89 let is_crate_root = path == "/lib.rs" || path == "/main.rs";
95 90
96 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 91 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
97 let file_id = Arc::make_mut(&mut self.file_map).add(path.clone()); 92 let file_id = FileId(self.file_counter);
93 self.file_counter += 1;
98 let text = Arc::new(text.to_string()); 94 let text = Arc::new(text.to_string());
99 self.set_file_text(file_id, text); 95 self.set_file_text(file_id, text);
100 self.set_file_relative_path(file_id, path.clone()); 96 self.set_file_relative_path(file_id, path.clone());
@@ -141,7 +137,7 @@ impl Default for MockDatabase {
141 events: Default::default(), 137 events: Default::default(),
142 runtime: salsa::Runtime::default(), 138 runtime: salsa::Runtime::default(),
143 interner: Default::default(), 139 interner: Default::default(),
144 file_map: Default::default(), 140 file_counter: 0,
145 }; 141 };
146 db.set_crate_graph(Default::default()); 142 db.set_crate_graph(Default::default());
147 db 143 db
@@ -154,7 +150,7 @@ impl salsa::ParallelDatabase for MockDatabase {
154 events: Default::default(), 150 events: Default::default(),
155 runtime: self.runtime.snapshot(self), 151 runtime: self.runtime.snapshot(self),
156 interner: Arc::clone(&self.interner), 152 interner: Arc::clone(&self.interner),
157 file_map: Arc::clone(&self.file_map), 153 file_counter: self.file_counter,
158 }) 154 })
159 } 155 }
160} 156}
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 971f71637..3d420467c 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -19,11 +19,12 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
19 (db.item_map(krate.crate_id), module_id) 19 (db.item_map(krate.crate_id), module_id)
20} 20}
21 21
22fn item_map_custom_crate_root(fixture: &str, root: &str) -> (Arc<ItemMap>, ModuleId) { 22/// Sets the crate root to the file of the cursor marker
23fn item_map_custom_crate_root(fixture: &str) -> (Arc<ItemMap>, ModuleId) {
23 let (mut db, pos) = MockDatabase::with_position(fixture); 24 let (mut db, pos) = MockDatabase::with_position(fixture);
24 25
25 let mut crate_graph = CrateGraph::default(); 26 let mut crate_graph = CrateGraph::default();
26 crate_graph.add_crate_root(db.file_id(root)); 27 crate_graph.add_crate_root(pos.file_id);
27 db.set_crate_graph(Arc::new(crate_graph)); 28 db.set_crate_graph(Arc::new(crate_graph));
28 29
29 let module = crate::source_binder::module_from_position(&db, pos).unwrap(); 30 let module = crate::source_binder::module_from_position(&db, pos).unwrap();
@@ -152,14 +153,11 @@ fn module_resolution_works_for_non_standard_filenames() {
152 " 153 "
153 //- /my_library.rs 154 //- /my_library.rs
154 mod foo; 155 mod foo;
155
156 use self::foo::Bar; 156 use self::foo::Bar;
157 <|> 157 <|>
158
159 //- /foo/mod.rs 158 //- /foo/mod.rs
160 pub struct Bar; 159 pub struct Bar;
161 ", 160 ",
162 "/my_library.rs",
163 ); 161 );
164 check_module_item_map( 162 check_module_item_map(
165 &item_map, 163 &item_map,