diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-05 07:53:08 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-05 07:53:08 +0000 |
commit | 4d4c46aff8f9a7ce8c2f91fbe6c7c363f5d3e08c (patch) | |
tree | 90473c4a67ac70ee40fde54a25b11d7768c41593 /crates/ra_ide_api/src/mock_analysis.rs | |
parent | 94d5d0d7e893a50bdd22ce4366ca15f083218d22 (diff) | |
parent | de4c5e381fb1adc25143dcd67af6c87f6d9789ae (diff) |
Merge #742
742: Extern crate r=matklad a=flodiebold
This implements `extern crate` declarations by lowering them to (absolute) imports, and adds support for absolute paths. It also extracts the extern prelude from the per-module item map, and handles the special case of extern crates in the crate root adding to the extern prelude.
This means we finally resolve `Arc`, so it fixes #523 :smile:
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/mock_analysis.rs')
-rw-r--r-- | crates/ra_ide_api/src/mock_analysis.rs | 12 |
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 | } |