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.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/ra_project_model/src/json_project.rs b/crates/ra_project_model/src/json_project.rs
new file mode 100644
index 000000000..9a9eb9e1f
--- /dev/null
+++ b/crates/ra_project_model/src/json_project.rs
@@ -0,0 +1,49 @@
1use std::path::PathBuf;
2
3use serde::Deserialize;
4
5/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
6/// all roots. Roots might be nested.
7#[derive(Clone, Debug, Deserialize)]
8#[serde(transparent)]
9pub struct Root {
10 pub(crate) path: PathBuf,
11}
12
13/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
14/// useful in creating the crate graph.
15#[derive(Clone, Debug, Deserialize)]
16pub struct Crate {
17 pub(crate) root_module: PathBuf,
18 pub(crate) edition: Edition,
19 pub(crate) deps: Vec<Dep>,
20}
21
22#[derive(Clone, Copy, Debug, Deserialize)]
23#[serde(rename = "edition")]
24pub enum Edition {
25 #[serde(rename = "2015")]
26 Edition2015,
27 #[serde(rename = "2018")]
28 Edition2018,
29}
30
31/// Identifies a crate by position in the crates array.
32#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd)]
33#[serde(transparent)]
34pub struct CrateId(pub usize);
35
36/// A dependency of a crate, identified by its id in the crates array and name.
37#[derive(Clone, Debug, Deserialize)]
38pub struct Dep {
39 #[serde(rename = "crate")]
40 pub(crate) krate: CrateId,
41 pub(crate) name: String,
42}
43
44/// Roots and crates that compose this Rust project.
45#[derive(Clone, Debug, Deserialize)]
46pub struct JsonProject {
47 pub(crate) roots: Vec<Root>,
48 pub(crate) crates: Vec<Crate>,
49}