diff options
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index e9c0c83db..ec8574952 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -185,10 +185,12 @@ impl ProjectWorkspace { | |||
185 | let mut crate_graph = CrateGraph::default(); | 185 | let mut crate_graph = CrateGraph::default(); |
186 | match self { | 186 | match self { |
187 | ProjectWorkspace::Json { project } => { | 187 | ProjectWorkspace::Json { project } => { |
188 | let mut crates = FxHashMap::default(); | 188 | let crates: FxHashMap<_, _> = project |
189 | for (id, krate) in project.crates.iter().enumerate() { | 189 | .crates |
190 | let crate_id = json_project::CrateId(id); | 190 | .iter() |
191 | if let Some(file_id) = load(&krate.root_module) { | 191 | .enumerate() |
192 | .filter_map(|(seq_index, krate)| { | ||
193 | let file_id = load(&krate.root_module)?; | ||
192 | let edition = match krate.edition { | 194 | let edition = match krate.edition { |
193 | json_project::Edition::Edition2015 => Edition::Edition2015, | 195 | json_project::Edition::Edition2015 => Edition::Edition2015, |
194 | json_project::Edition::Edition2018 => Edition::Edition2018, | 196 | json_project::Edition::Edition2018 => Edition::Edition2018, |
@@ -218,8 +220,8 @@ impl ProjectWorkspace { | |||
218 | .clone() | 220 | .clone() |
219 | .map(|it| proc_macro_client.by_dylib_path(&it)); | 221 | .map(|it| proc_macro_client.by_dylib_path(&it)); |
220 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env | 222 | // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env |
221 | crates.insert( | 223 | Some(( |
222 | crate_id, | 224 | json_project::CrateId(seq_index), |
223 | crate_graph.add_crate_root( | 225 | crate_graph.add_crate_root( |
224 | file_id, | 226 | file_id, |
225 | edition, | 227 | edition, |
@@ -230,9 +232,9 @@ impl ProjectWorkspace { | |||
230 | extern_source, | 232 | extern_source, |
231 | proc_macro.unwrap_or_default(), | 233 | proc_macro.unwrap_or_default(), |
232 | ), | 234 | ), |
233 | ); | 235 | )) |
234 | } | 236 | }) |
235 | } | 237 | .collect(); |
236 | 238 | ||
237 | for (id, krate) in project.crates.iter().enumerate() { | 239 | for (id, krate) in project.crates.iter().enumerate() { |
238 | for dep in &krate.deps { | 240 | for dep in &krate.deps { |
@@ -256,9 +258,11 @@ impl ProjectWorkspace { | |||
256 | } | 258 | } |
257 | } | 259 | } |
258 | ProjectWorkspace::Cargo { cargo, sysroot } => { | 260 | ProjectWorkspace::Cargo { cargo, sysroot } => { |
259 | let mut sysroot_crates = FxHashMap::default(); | 261 | let sysroot_crates: FxHashMap<_, _> = sysroot |
260 | for krate in sysroot.crates() { | 262 | .crates() |
261 | if let Some(file_id) = load(&sysroot[krate].root) { | 263 | .filter_map(|krate| { |
264 | let file_id = load(&sysroot[krate].root)?; | ||
265 | |||
262 | // Crates from sysroot have `cfg(test)` disabled | 266 | // Crates from sysroot have `cfg(test)` disabled |
263 | let cfg_options = { | 267 | let cfg_options = { |
264 | let mut opts = default_cfg_options.clone(); | 268 | let mut opts = default_cfg_options.clone(); |
@@ -269,22 +273,22 @@ impl ProjectWorkspace { | |||
269 | let env = Env::default(); | 273 | let env = Env::default(); |
270 | let extern_source = ExternSource::default(); | 274 | let extern_source = ExternSource::default(); |
271 | let proc_macro = vec![]; | 275 | let proc_macro = vec![]; |
276 | let crate_name = CrateName::new(&sysroot[krate].name) | ||
277 | .expect("Sysroot crate names should not contain dashes"); | ||
272 | 278 | ||
273 | let crate_id = crate_graph.add_crate_root( | 279 | let crate_id = crate_graph.add_crate_root( |
274 | file_id, | 280 | file_id, |
275 | Edition::Edition2018, | 281 | Edition::Edition2018, |
276 | Some( | 282 | Some(crate_name), |
277 | CrateName::new(&sysroot[krate].name) | ||
278 | .expect("Sysroot crate names should not contain dashes"), | ||
279 | ), | ||
280 | cfg_options, | 283 | cfg_options, |
281 | env, | 284 | env, |
282 | extern_source, | 285 | extern_source, |
283 | proc_macro, | 286 | proc_macro, |
284 | ); | 287 | ); |
285 | sysroot_crates.insert(krate, crate_id); | 288 | Some((krate, crate_id)) |
286 | } | 289 | }) |
287 | } | 290 | .collect(); |
291 | |||
288 | for from in sysroot.crates() { | 292 | for from in sysroot.crates() { |
289 | for &to in sysroot[from].deps.iter() { | 293 | for &to in sysroot[from].deps.iter() { |
290 | let name = &sysroot[to].name; | 294 | let name = &sysroot[to].name; |