diff options
Diffstat (limited to 'crates/project_model')
-rw-r--r-- | crates/project_model/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/project_model/src/lib.rs | 16 | ||||
-rw-r--r-- | crates/project_model/src/project_json.rs | 7 |
3 files changed, 18 insertions, 7 deletions
diff --git a/crates/project_model/Cargo.toml b/crates/project_model/Cargo.toml index 8bee398d9..2d53bcbcc 100644 --- a/crates/project_model/Cargo.toml +++ b/crates/project_model/Cargo.toml | |||
@@ -12,7 +12,7 @@ doctest = false | |||
12 | [dependencies] | 12 | [dependencies] |
13 | log = "0.4.8" | 13 | log = "0.4.8" |
14 | rustc-hash = "1.1.0" | 14 | rustc-hash = "1.1.0" |
15 | cargo_metadata = "0.11.1" | 15 | cargo_metadata = "0.12.0" |
16 | serde = { version = "1.0.106", features = ["derive"] } | 16 | serde = { version = "1.0.106", features = ["derive"] } |
17 | serde_json = "1.0.48" | 17 | serde_json = "1.0.48" |
18 | anyhow = "1.0.26" | 18 | anyhow = "1.0.26" |
diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs index d1e7602fc..e92cfea59 100644 --- a/crates/project_model/src/lib.rs +++ b/crates/project_model/src/lib.rs | |||
@@ -13,7 +13,7 @@ use std::{ | |||
13 | }; | 13 | }; |
14 | 14 | ||
15 | use anyhow::{bail, Context, Result}; | 15 | use anyhow::{bail, Context, Result}; |
16 | use base_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId}; | 16 | use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId}; |
17 | use cfg::CfgOptions; | 17 | use cfg::CfgOptions; |
18 | use paths::{AbsPath, AbsPathBuf}; | 18 | use paths::{AbsPath, AbsPathBuf}; |
19 | use rustc_hash::{FxHashMap, FxHashSet}; | 19 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -335,8 +335,7 @@ impl ProjectWorkspace { | |||
335 | crate_graph.add_crate_root( | 335 | crate_graph.add_crate_root( |
336 | file_id, | 336 | file_id, |
337 | krate.edition, | 337 | krate.edition, |
338 | // FIXME json definitions can store the crate name | 338 | krate.display_name.clone(), |
339 | None, | ||
340 | cfg_options, | 339 | cfg_options, |
341 | env, | 340 | env, |
342 | proc_macro.unwrap_or_default(), | 341 | proc_macro.unwrap_or_default(), |
@@ -408,10 +407,12 @@ impl ProjectWorkspace { | |||
408 | .map(|it| proc_macro_client.by_dylib_path(&it)) | 407 | .map(|it| proc_macro_client.by_dylib_path(&it)) |
409 | .unwrap_or_default(); | 408 | .unwrap_or_default(); |
410 | 409 | ||
410 | let display_name = | ||
411 | CrateDisplayName::from_canonical_name(cargo[pkg].name.clone()); | ||
411 | let crate_id = crate_graph.add_crate_root( | 412 | let crate_id = crate_graph.add_crate_root( |
412 | file_id, | 413 | file_id, |
413 | edition, | 414 | edition, |
414 | Some(CrateName::normalize_dashes(&cargo[pkg].name)), | 415 | Some(display_name), |
415 | cfg_options, | 416 | cfg_options, |
416 | env, | 417 | env, |
417 | proc_macro.clone(), | 418 | proc_macro.clone(), |
@@ -485,6 +486,11 @@ impl ProjectWorkspace { | |||
485 | } | 486 | } |
486 | } | 487 | } |
487 | } | 488 | } |
489 | if crate_graph.patch_cfg_if() { | ||
490 | log::debug!("Patched std to depend on cfg-if") | ||
491 | } else { | ||
492 | log::debug!("Did not patch std to depend on cfg-if") | ||
493 | } | ||
488 | crate_graph | 494 | crate_graph |
489 | } | 495 | } |
490 | } | 496 | } |
@@ -551,7 +557,7 @@ fn sysroot_to_crate_graph( | |||
551 | let crate_id = crate_graph.add_crate_root( | 557 | let crate_id = crate_graph.add_crate_root( |
552 | file_id, | 558 | file_id, |
553 | Edition::Edition2018, | 559 | Edition::Edition2018, |
554 | Some(name), | 560 | Some(name.into()), |
555 | cfg_options.clone(), | 561 | cfg_options.clone(), |
556 | env, | 562 | env, |
557 | proc_macro, | 563 | proc_macro, |
diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index a6895ecdd..aab279223 100644 --- a/crates/project_model/src/project_json.rs +++ b/crates/project_model/src/project_json.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::path::PathBuf; | 3 | use std::path::PathBuf; |
4 | 4 | ||
5 | use base_db::{CrateId, CrateName, Dependency, Edition}; | 5 | use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition}; |
6 | use paths::{AbsPath, AbsPathBuf}; | 6 | use paths::{AbsPath, AbsPathBuf}; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | use serde::{de, Deserialize}; | 8 | use serde::{de, Deserialize}; |
@@ -21,6 +21,7 @@ pub struct ProjectJson { | |||
21 | /// useful in creating the crate graph. | 21 | /// useful in creating the crate graph. |
22 | #[derive(Clone, Debug, Eq, PartialEq)] | 22 | #[derive(Clone, Debug, Eq, PartialEq)] |
23 | pub struct Crate { | 23 | pub struct Crate { |
24 | pub(crate) display_name: Option<CrateDisplayName>, | ||
24 | pub(crate) root_module: AbsPathBuf, | 25 | pub(crate) root_module: AbsPathBuf, |
25 | pub(crate) edition: Edition, | 26 | pub(crate) edition: Edition, |
26 | pub(crate) deps: Vec<Dependency>, | 27 | pub(crate) deps: Vec<Dependency>, |
@@ -68,6 +69,9 @@ impl ProjectJson { | |||
68 | }; | 69 | }; |
69 | 70 | ||
70 | Crate { | 71 | Crate { |
72 | display_name: crate_data | ||
73 | .display_name | ||
74 | .map(CrateDisplayName::from_canonical_name), | ||
71 | root_module, | 75 | root_module, |
72 | edition: crate_data.edition.into(), | 76 | edition: crate_data.edition.into(), |
73 | deps: crate_data | 77 | deps: crate_data |
@@ -114,6 +118,7 @@ pub struct ProjectJsonData { | |||
114 | 118 | ||
115 | #[derive(Deserialize)] | 119 | #[derive(Deserialize)] |
116 | struct CrateData { | 120 | struct CrateData { |
121 | display_name: Option<String>, | ||
117 | root_module: PathBuf, | 122 | root_module: PathBuf, |
118 | edition: EditionData, | 123 | edition: EditionData, |
119 | deps: Vec<DepData>, | 124 | deps: Vec<DepData>, |