diff options
Diffstat (limited to 'crates/ra_project_model/src/project_json.rs')
-rw-r--r-- | crates/ra_project_model/src/project_json.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs index 4b5dcd634..b0fe09333 100644 --- a/crates/ra_project_model/src/project_json.rs +++ b/crates/ra_project_model/src/project_json.rs | |||
@@ -4,13 +4,13 @@ use std::path::PathBuf; | |||
4 | 4 | ||
5 | use paths::{AbsPath, AbsPathBuf}; | 5 | use paths::{AbsPath, AbsPathBuf}; |
6 | use ra_cfg::CfgOptions; | 6 | use ra_cfg::CfgOptions; |
7 | use ra_db::{CrateId, Dependency, Edition}; | 7 | use ra_db::{CrateId, CrateName, Dependency, Edition}; |
8 | use rustc_hash::FxHashSet; | 8 | use rustc_hash::FxHashSet; |
9 | use serde::Deserialize; | 9 | use serde::{de, Deserialize}; |
10 | use stdx::split_delim; | 10 | use stdx::split_delim; |
11 | 11 | ||
12 | /// Roots and crates that compose this Rust project. | 12 | /// Roots and crates that compose this Rust project. |
13 | #[derive(Clone, Debug)] | 13 | #[derive(Clone, Debug, Eq, PartialEq)] |
14 | pub struct ProjectJson { | 14 | pub struct ProjectJson { |
15 | pub(crate) roots: Vec<Root>, | 15 | pub(crate) roots: Vec<Root>, |
16 | pub(crate) crates: Vec<Crate>, | 16 | pub(crate) crates: Vec<Crate>, |
@@ -18,14 +18,14 @@ pub struct ProjectJson { | |||
18 | 18 | ||
19 | /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in | 19 | /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in |
20 | /// all roots. Roots might be nested. | 20 | /// all roots. Roots might be nested. |
21 | #[derive(Clone, Debug)] | 21 | #[derive(Clone, Debug, Eq, PartialEq)] |
22 | pub struct Root { | 22 | pub struct Root { |
23 | pub(crate) path: AbsPathBuf, | 23 | pub(crate) path: AbsPathBuf, |
24 | } | 24 | } |
25 | 25 | ||
26 | /// A crate points to the root module of a crate and lists the dependencies of the crate. This is | 26 | /// A crate points to the root module of a crate and lists the dependencies of the crate. This is |
27 | /// useful in creating the crate graph. | 27 | /// useful in creating the crate graph. |
28 | #[derive(Clone, Debug)] | 28 | #[derive(Clone, Debug, Eq, PartialEq)] |
29 | pub struct Crate { | 29 | pub struct Crate { |
30 | pub(crate) root_module: AbsPathBuf, | 30 | pub(crate) root_module: AbsPathBuf, |
31 | pub(crate) edition: Edition, | 31 | pub(crate) edition: Edition, |
@@ -50,7 +50,7 @@ impl ProjectJson { | |||
50 | .into_iter() | 50 | .into_iter() |
51 | .map(|dep_data| Dependency { | 51 | .map(|dep_data| Dependency { |
52 | crate_id: CrateId(dep_data.krate as u32), | 52 | crate_id: CrateId(dep_data.krate as u32), |
53 | name: dep_data.name.into(), | 53 | name: dep_data.name, |
54 | }) | 54 | }) |
55 | .collect::<Vec<_>>(), | 55 | .collect::<Vec<_>>(), |
56 | cfg: { | 56 | cfg: { |
@@ -113,5 +113,14 @@ struct DepData { | |||
113 | /// Identifies a crate by position in the crates array. | 113 | /// Identifies a crate by position in the crates array. |
114 | #[serde(rename = "crate")] | 114 | #[serde(rename = "crate")] |
115 | krate: usize, | 115 | krate: usize, |
116 | name: String, | 116 | #[serde(deserialize_with = "deserialize_crate_name")] |
117 | name: CrateName, | ||
118 | } | ||
119 | |||
120 | fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error> | ||
121 | where | ||
122 | D: de::Deserializer<'de>, | ||
123 | { | ||
124 | let name = String::deserialize(de)?; | ||
125 | CrateName::new(&name).map_err(|err| de::Error::custom(format!("invalid crate name: {:?}", err))) | ||
117 | } | 126 | } |