aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/mock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/mock.rs')
-rw-r--r--crates/ra_hir/src/mock.rs68
1 files changed, 0 insertions, 68 deletions
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 8d98f88ce..ab97a09b9 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -77,12 +77,6 @@ impl MockDatabase {
77 (db, source_root, file_id) 77 (db, source_root, file_id)
78 } 78 }
79 79
80 pub fn with_position(fixture: &str) -> (MockDatabase, FilePosition) {
81 let (db, position) = MockDatabase::from_fixture(fixture);
82 let position = position.expect("expected a marker ( <|> )");
83 (db, position)
84 }
85
86 pub fn file_id_of(&self, path: &str) -> FileId { 80 pub fn file_id_of(&self, path: &str) -> FileId {
87 match self.files.get(path) { 81 match self.files.get(path) {
88 Some(it) => *it, 82 Some(it) => *it,
@@ -90,25 +84,6 @@ impl MockDatabase {
90 } 84 }
91 } 85 }
92 86
93 pub fn set_crate_graph_from_fixture(&mut self, graph: CrateGraphFixture) {
94 let mut ids = FxHashMap::default();
95 let mut crate_graph = CrateGraph::default();
96 for (crate_name, (crate_root, edition, cfg_options, _)) in graph.0.iter() {
97 let crate_root = self.file_id_of(&crate_root);
98 let crate_id = crate_graph.add_crate_root(crate_root, *edition, cfg_options.clone());
99 Arc::make_mut(&mut self.crate_names).insert(crate_id, crate_name.clone());
100 ids.insert(crate_name, crate_id);
101 }
102 for (crate_name, (_, _, _, deps)) in graph.0.iter() {
103 let from = ids[crate_name];
104 for dep in deps {
105 let to = ids[dep];
106 crate_graph.add_dep(from, dep.as_str().into(), to).unwrap();
107 }
108 }
109 self.set_crate_graph(Arc::new(crate_graph))
110 }
111
112 pub fn diagnostics(&self) -> String { 87 pub fn diagnostics(&self) -> String {
113 let mut buf = String::new(); 88 let mut buf = String::new();
114 let mut files: Vec<FileId> = self.files.values().copied().collect(); 89 let mut files: Vec<FileId> = self.files.values().copied().collect();
@@ -285,46 +260,3 @@ impl MockDatabase {
285 .collect() 260 .collect()
286 } 261 }
287} 262}
288
289#[derive(Default)]
290pub struct CrateGraphFixture(pub Vec<(String, (String, Edition, CfgOptions, Vec<String>))>);
291
292#[macro_export]
293macro_rules! crate_graph {
294 ($(
295 $crate_name:literal: (
296 $crate_path:literal,
297 $($edition:literal,)?
298 [$($dep:literal),*]
299 $(, cfg = {
300 $($key:literal $(= $value:literal)?),*
301 $(,)?
302 })?
303 ),
304 )*) => {{
305 let mut res = $crate::mock::CrateGraphFixture::default();
306 $(
307 #[allow(unused_mut, unused_assignments)]
308 let mut edition = ra_db::Edition::Edition2018;
309 $(edition = ra_db::Edition::from_string($edition);)?
310 let cfg_options = {
311 #[allow(unused_mut)]
312 let mut cfg = ::ra_cfg::CfgOptions::default();
313 $(
314 $(
315 if 0 == 0 $(+ { drop($value); 1})? {
316 cfg.insert_atom($key.into());
317 }
318 $(cfg.insert_key_value($key.into(), $value.into());)?
319 )*
320 )?
321 cfg
322 };
323 res.0.push((
324 $crate_name.to_string(),
325 ($crate_path.to_string(), edition, cfg_options, vec![$($dep.to_string()),*])
326 ));
327 )*
328 res
329 }}
330}