aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/json_project.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/json_project.rs')
-rw-r--r--crates/ra_project_model/src/json_project.rs55
1 files changed, 47 insertions, 8 deletions
diff --git a/crates/ra_project_model/src/json_project.rs b/crates/ra_project_model/src/json_project.rs
index b030c8a6a..ee2de4c25 100644
--- a/crates/ra_project_model/src/json_project.rs
+++ b/crates/ra_project_model/src/json_project.rs
@@ -2,9 +2,16 @@
2 2
3use std::path::PathBuf; 3use std::path::PathBuf;
4 4
5use rustc_hash::{FxHashMap, FxHashSet}; 5use rustc_hash::FxHashSet;
6use serde::Deserialize; 6use serde::Deserialize;
7 7
8/// Roots and crates that compose this Rust project.
9#[derive(Clone, Debug, Deserialize)]
10pub struct JsonProject {
11 pub(crate) roots: Vec<Root>,
12 pub(crate) crates: Vec<Crate>,
13}
14
8/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in 15/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
9/// all roots. Roots might be nested. 16/// all roots. Roots might be nested.
10#[derive(Clone, Debug, Deserialize)] 17#[derive(Clone, Debug, Deserialize)]
@@ -20,8 +27,10 @@ pub struct Crate {
20 pub(crate) root_module: PathBuf, 27 pub(crate) root_module: PathBuf,
21 pub(crate) edition: Edition, 28 pub(crate) edition: Edition,
22 pub(crate) deps: Vec<Dep>, 29 pub(crate) deps: Vec<Dep>,
23 pub(crate) atom_cfgs: FxHashSet<String>, 30
24 pub(crate) key_value_cfgs: FxHashMap<String, String>, 31 #[serde(default)]
32 pub(crate) cfg: FxHashSet<String>,
33
25 pub(crate) out_dir: Option<PathBuf>, 34 pub(crate) out_dir: Option<PathBuf>,
26 pub(crate) proc_macro_dylib_path: Option<PathBuf>, 35 pub(crate) proc_macro_dylib_path: Option<PathBuf>,
27} 36}
@@ -48,9 +57,39 @@ pub struct Dep {
48 pub(crate) name: String, 57 pub(crate) name: String,
49} 58}
50 59
51/// Roots and crates that compose this Rust project. 60#[cfg(test)]
52#[derive(Clone, Debug, Deserialize)] 61mod tests {
53pub struct JsonProject { 62 use super::*;
54 pub(crate) roots: Vec<Root>, 63 use serde_json::json;
55 pub(crate) crates: Vec<Crate>, 64
65 #[test]
66 fn test_crate_deserialization() {
67 let raw_json = json!( {
68 "crate_id": 2,
69 "root_module": "this/is/a/file/path.rs",
70 "deps": [
71 {
72 "crate": 1,
73 "name": "some_dep_crate"
74 },
75 ],
76 "edition": "2015",
77 "cfg": [
78 "atom_1",
79 "atom_2",
80 "feature=feature_1",
81 "feature=feature_2",
82 "other=value",
83 ],
84
85 });
86
87 let krate: Crate = serde_json::from_value(raw_json).unwrap();
88
89 assert!(krate.cfg.contains(&"atom_1".to_string()));
90 assert!(krate.cfg.contains(&"atom_2".to_string()));
91 assert!(krate.cfg.contains(&"feature=feature_1".to_string()));
92 assert!(krate.cfg.contains(&"feature=feature_2".to_string()));
93 assert!(krate.cfg.contains(&"other=value".to_string()));
94 }
56} 95}