aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/mock_analysis.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs
index 0f2d22ab2..834b30541 100644
--- a/crates/ra_ide_api/src/mock_analysis.rs
+++ b/crates/ra_ide_api/src/mock_analysis.rs
@@ -86,17 +86,25 @@ impl MockAnalysis {
86 let mut change = AnalysisChange::new(); 86 let mut change = AnalysisChange::new();
87 change.add_root(source_root, true); 87 change.add_root(source_root, true);
88 let mut crate_graph = CrateGraph::default(); 88 let mut crate_graph = CrateGraph::default();
89 let mut root_crate = None;
89 for (i, (path, contents)) in self.files.into_iter().enumerate() { 90 for (i, (path, contents)) in self.files.into_iter().enumerate() {
90 assert!(path.starts_with('/')); 91 assert!(path.starts_with('/'));
91 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 92 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
92 let file_id = FileId(i as u32 + 1); 93 let file_id = FileId(i as u32 + 1);
93 if path == "/lib.rs" || path == "/main.rs" { 94 if path == "/lib.rs" || path == "/main.rs" {
94 crate_graph.add_crate_root(file_id); 95 root_crate = Some(crate_graph.add_crate_root(file_id));
96 } else if path.ends_with("/lib.rs") {
97 let other_crate = crate_graph.add_crate_root(file_id);
98 let crate_name = path.parent().unwrap().file_name().unwrap();
99 if let Some(root_crate) = root_crate {
100 crate_graph
101 .add_dep(root_crate, crate_name.into(), other_crate)
102 .unwrap();
103 }
95 } 104 }
96 change.add_file(source_root, file_id, path, Arc::new(contents)); 105 change.add_file(source_root, file_id, path, Arc::new(contents));
97 } 106 }
98 change.set_crate_graph(crate_graph); 107 change.set_crate_graph(crate_graph);
99 // change.set_file_resolver(Arc::new(file_map));
100 host.apply_change(change); 108 host.apply_change(change);
101 host 109 host
102 } 110 }