aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/project_json.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/project_json.rs')
-rw-r--r--crates/ra_project_model/src/project_json.rs43
1 files changed, 28 insertions, 15 deletions
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs
index 778cc84ef..e9a333191 100644
--- a/crates/ra_project_model/src/project_json.rs
+++ b/crates/ra_project_model/src/project_json.rs
@@ -5,24 +5,16 @@ use std::path::PathBuf;
5use paths::{AbsPath, AbsPathBuf}; 5use paths::{AbsPath, AbsPathBuf};
6use ra_cfg::CfgOptions; 6use ra_cfg::CfgOptions;
7use ra_db::{CrateId, CrateName, Dependency, Edition}; 7use ra_db::{CrateId, CrateName, Dependency, Edition};
8use rustc_hash::FxHashSet; 8use rustc_hash::{FxHashMap, FxHashSet};
9use serde::{de, Deserialize}; 9use serde::{de, Deserialize};
10use stdx::split_delim; 10use 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, Eq, PartialEq)] 13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct ProjectJson { 14pub struct ProjectJson {
15 pub(crate) roots: Vec<Root>,
16 pub(crate) crates: Vec<Crate>, 15 pub(crate) crates: Vec<Crate>,
17} 16}
18 17
19/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
20/// all roots. Roots might be nested.
21#[derive(Clone, Debug, Eq, PartialEq)]
22pub struct Root {
23 pub(crate) path: AbsPathBuf,
24}
25
26/// A crate points to the root module of a crate and lists the dependencies of the crate. This is 18/// 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. 19/// useful in creating the crate graph.
28#[derive(Clone, Debug, Eq, PartialEq)] 20#[derive(Clone, Debug, Eq, PartialEq)]
@@ -32,15 +24,16 @@ pub struct Crate {
32 pub(crate) deps: Vec<Dependency>, 24 pub(crate) deps: Vec<Dependency>,
33 pub(crate) cfg: CfgOptions, 25 pub(crate) cfg: CfgOptions,
34 pub(crate) target: Option<String>, 26 pub(crate) target: Option<String>,
35 pub(crate) out_dir: Option<AbsPathBuf>, 27 pub(crate) env: FxHashMap<String, String>,
36 pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>, 28 pub(crate) proc_macro_dylib_path: Option<AbsPathBuf>,
37 pub(crate) is_workspace_member: bool, 29 pub(crate) is_workspace_member: bool,
30 pub(crate) include: Vec<AbsPathBuf>,
31 pub(crate) exclude: Vec<AbsPathBuf>,
38} 32}
39 33
40impl ProjectJson { 34impl ProjectJson {
41 pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { 35 pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
42 ProjectJson { 36 ProjectJson {
43 roots: data.roots.into_iter().map(|path| Root { path: base.join(path) }).collect(),
44 crates: data 37 crates: data
45 .crates 38 .crates
46 .into_iter() 39 .into_iter()
@@ -50,8 +43,19 @@ impl ProjectJson {
50 && !crate_data.root_module.starts_with("..") 43 && !crate_data.root_module.starts_with("..")
51 || crate_data.root_module.starts_with(base) 44 || crate_data.root_module.starts_with(base)
52 }); 45 });
46 let root_module = base.join(crate_data.root_module);
47 let (include, exclude) = match crate_data.source {
48 Some(src) => {
49 let absolutize = |dirs: Vec<PathBuf>| {
50 dirs.into_iter().map(|it| base.join(it)).collect::<Vec<_>>()
51 };
52 (absolutize(src.include_dirs), absolutize(src.exclude_dirs))
53 }
54 None => (vec![root_module.parent().unwrap().to_path_buf()], Vec::new()),
55 };
56
53 Crate { 57 Crate {
54 root_module: base.join(crate_data.root_module), 58 root_module,
55 edition: crate_data.edition.into(), 59 edition: crate_data.edition.into(),
56 deps: crate_data 60 deps: crate_data
57 .deps 61 .deps
@@ -74,11 +78,13 @@ impl ProjectJson {
74 cfg 78 cfg
75 }, 79 },
76 target: crate_data.target, 80 target: crate_data.target,
77 out_dir: crate_data.out_dir.map(|it| base.join(it)), 81 env: crate_data.env,
78 proc_macro_dylib_path: crate_data 82 proc_macro_dylib_path: crate_data
79 .proc_macro_dylib_path 83 .proc_macro_dylib_path
80 .map(|it| base.join(it)), 84 .map(|it| base.join(it)),
81 is_workspace_member, 85 is_workspace_member,
86 include,
87 exclude,
82 } 88 }
83 }) 89 })
84 .collect::<Vec<_>>(), 90 .collect::<Vec<_>>(),
@@ -88,7 +94,6 @@ impl ProjectJson {
88 94
89#[derive(Deserialize)] 95#[derive(Deserialize)]
90pub struct ProjectJsonData { 96pub struct ProjectJsonData {
91 roots: Vec<PathBuf>,
92 crates: Vec<CrateData>, 97 crates: Vec<CrateData>,
93} 98}
94 99
@@ -100,9 +105,11 @@ struct CrateData {
100 #[serde(default)] 105 #[serde(default)]
101 cfg: FxHashSet<String>, 106 cfg: FxHashSet<String>,
102 target: Option<String>, 107 target: Option<String>,
103 out_dir: Option<PathBuf>, 108 #[serde(default)]
109 env: FxHashMap<String, String>,
104 proc_macro_dylib_path: Option<PathBuf>, 110 proc_macro_dylib_path: Option<PathBuf>,
105 is_workspace_member: Option<bool>, 111 is_workspace_member: Option<bool>,
112 source: Option<CrateSource>,
106} 113}
107 114
108#[derive(Deserialize)] 115#[derive(Deserialize)]
@@ -132,6 +139,12 @@ struct DepData {
132 name: CrateName, 139 name: CrateName,
133} 140}
134 141
142#[derive(Deserialize)]
143struct CrateSource {
144 include_dirs: Vec<PathBuf>,
145 exclude_dirs: Vec<PathBuf>,
146}
147
135fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error> 148fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error>
136where 149where
137 D: de::Deserializer<'de>, 150 D: de::Deserializer<'de>,