aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/json_project.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-07 11:36:04 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-07 11:36:04 +0000
commit5232099977d07492c1b6d5e6163c70d4f6eb07df (patch)
tree0660079034d3c2f30147e946f2c473d2f651eef2 /crates/ra_project_model/src/json_project.rs
parentb94e1eee8341cb2a16b89711d65b382549fd2bde (diff)
parent4cd757c1e32f0cf1f281b82cd55615d0e47edb24 (diff)
Merge #939
939: Initial implementation of project-lock.json. r=davidtwco a=davidtwco Fixes #792. This PR adds a initial implementation of project-lock.json, a build system agnostic method of specifying the crate graph and roots. Co-authored-by: David Wood <[email protected]>
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}