aboutsummaryrefslogtreecommitdiff
path: root/crates/project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/project_model')
-rw-r--r--crates/project_model/Cargo.toml2
-rw-r--r--crates/project_model/src/lib.rs16
-rw-r--r--crates/project_model/src/project_json.rs7
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]
13log = "0.4.8" 13log = "0.4.8"
14rustc-hash = "1.1.0" 14rustc-hash = "1.1.0"
15cargo_metadata = "0.11.1" 15cargo_metadata = "0.12.0"
16serde = { version = "1.0.106", features = ["derive"] } 16serde = { version = "1.0.106", features = ["derive"] }
17serde_json = "1.0.48" 17serde_json = "1.0.48"
18anyhow = "1.0.26" 18anyhow = "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
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use base_db::{CrateGraph, CrateId, CrateName, Edition, Env, FileId}; 16use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId};
17use cfg::CfgOptions; 17use cfg::CfgOptions;
18use paths::{AbsPath, AbsPathBuf}; 18use paths::{AbsPath, AbsPathBuf};
19use rustc_hash::{FxHashMap, FxHashSet}; 19use 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
3use std::path::PathBuf; 3use std::path::PathBuf;
4 4
5use base_db::{CrateId, CrateName, Dependency, Edition}; 5use base_db::{CrateDisplayName, CrateId, CrateName, Dependency, Edition};
6use paths::{AbsPath, AbsPathBuf}; 6use paths::{AbsPath, AbsPathBuf};
7use rustc_hash::FxHashMap; 7use rustc_hash::FxHashMap;
8use serde::{de, Deserialize}; 8use 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)]
23pub struct Crate { 23pub 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)]
116struct CrateData { 120struct 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>,