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.rs95
1 files changed, 0 insertions, 95 deletions
diff --git a/crates/ra_project_model/src/json_project.rs b/crates/ra_project_model/src/json_project.rs
deleted file mode 100644
index ee2de4c25..000000000
--- a/crates/ra_project_model/src/json_project.rs
+++ /dev/null
@@ -1,95 +0,0 @@
1//! FIXME: write short doc here
2
3use std::path::PathBuf;
4
5use rustc_hash::FxHashSet;
6use serde::Deserialize;
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
15/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
16/// all roots. Roots might be nested.
17#[derive(Clone, Debug, Deserialize)]
18#[serde(transparent)]
19pub struct Root {
20 pub(crate) path: PathBuf,
21}
22
23/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
24/// useful in creating the crate graph.
25#[derive(Clone, Debug, Deserialize)]
26pub struct Crate {
27 pub(crate) root_module: PathBuf,
28 pub(crate) edition: Edition,
29 pub(crate) deps: Vec<Dep>,
30
31 #[serde(default)]
32 pub(crate) cfg: FxHashSet<String>,
33
34 pub(crate) out_dir: Option<PathBuf>,
35 pub(crate) proc_macro_dylib_path: Option<PathBuf>,
36}
37
38#[derive(Clone, Copy, Debug, Deserialize)]
39#[serde(rename = "edition")]
40pub enum Edition {
41 #[serde(rename = "2015")]
42 Edition2015,
43 #[serde(rename = "2018")]
44 Edition2018,
45}
46
47/// Identifies a crate by position in the crates array.
48#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd)]
49#[serde(transparent)]
50pub struct CrateId(pub usize);
51
52/// A dependency of a crate, identified by its id in the crates array and name.
53#[derive(Clone, Debug, Deserialize)]
54pub struct Dep {
55 #[serde(rename = "crate")]
56 pub(crate) krate: CrateId,
57 pub(crate) name: String,
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63 use serde_json::json;
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 }
95}