diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 29 | ||||
-rw-r--r-- | crates/ra_project_model/src/project_json.rs | 34 |
2 files changed, 32 insertions, 31 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index cf46048e5..05f2e7b7a 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -7,7 +7,6 @@ mod sysroot; | |||
7 | use std::{ | 7 | use std::{ |
8 | fs::{self, read_dir, ReadDir}, | 8 | fs::{self, read_dir, ReadDir}, |
9 | io, | 9 | io, |
10 | path::Path, | ||
11 | process::{Command, Output}, | 10 | process::{Command, Output}, |
12 | }; | 11 | }; |
13 | 12 | ||
@@ -35,7 +34,7 @@ pub enum ProjectWorkspace { | |||
35 | /// `PackageRoot` describes a package root folder. | 34 | /// `PackageRoot` describes a package root folder. |
36 | /// Which may be an external dependency, or a member of | 35 | /// Which may be an external dependency, or a member of |
37 | /// the current workspace. | 36 | /// the current workspace. |
38 | #[derive(Debug, Clone)] | 37 | #[derive(Debug, Clone, Eq, PartialEq, Hash)] |
39 | pub struct PackageRoot { | 38 | pub struct PackageRoot { |
40 | /// Is a member of the current workspace | 39 | /// Is a member of the current workspace |
41 | pub is_member: bool, | 40 | pub is_member: bool, |
@@ -178,14 +177,16 @@ impl ProjectWorkspace { | |||
178 | pub fn to_roots(&self) -> Vec<PackageRoot> { | 177 | pub fn to_roots(&self) -> Vec<PackageRoot> { |
179 | match self { | 178 | match self { |
180 | ProjectWorkspace::Json { project } => project | 179 | ProjectWorkspace::Json { project } => project |
181 | .roots | 180 | .crates |
182 | .iter() | 181 | .iter() |
183 | .map(|r| { | 182 | .map(|krate| PackageRoot { |
184 | let path = r.path.clone(); | 183 | is_member: krate.is_workspace_member, |
185 | let include = vec![path]; | 184 | include: krate.include.clone(), |
186 | PackageRoot { is_member: true, include, exclude: Vec::new() } | 185 | exclude: krate.exclude.clone(), |
187 | }) | 186 | }) |
188 | .collect(), | 187 | .collect::<FxHashSet<_>>() |
188 | .into_iter() | ||
189 | .collect::<Vec<_>>(), | ||
189 | ProjectWorkspace::Cargo { cargo, sysroot } => cargo | 190 | ProjectWorkspace::Cargo { cargo, sysroot } => cargo |
190 | .packages() | 191 | .packages() |
191 | .map(|pkg| { | 192 | .map(|pkg| { |
@@ -505,18 +506,6 @@ impl ProjectWorkspace { | |||
505 | } | 506 | } |
506 | crate_graph | 507 | crate_graph |
507 | } | 508 | } |
508 | |||
509 | pub fn workspace_root_for(&self, path: &Path) -> Option<&AbsPath> { | ||
510 | match self { | ||
511 | ProjectWorkspace::Cargo { cargo, .. } => { | ||
512 | Some(cargo.workspace_root()).filter(|root| path.starts_with(root)) | ||
513 | } | ||
514 | ProjectWorkspace::Json { project: ProjectJson { roots, .. }, .. } => roots | ||
515 | .iter() | ||
516 | .find(|root| path.starts_with(&root.path)) | ||
517 | .map(|root| root.path.as_path()), | ||
518 | } | ||
519 | } | ||
520 | } | 509 | } |
521 | 510 | ||
522 | fn get_rustc_cfg_options(target: Option<&str>) -> CfgOptions { | 511 | fn get_rustc_cfg_options(target: Option<&str>) -> CfgOptions { |
diff --git a/crates/ra_project_model/src/project_json.rs b/crates/ra_project_model/src/project_json.rs index 778cc84ef..e0052ac6d 100644 --- a/crates/ra_project_model/src/project_json.rs +++ b/crates/ra_project_model/src/project_json.rs | |||
@@ -12,17 +12,9 @@ use stdx::split_delim; | |||
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)] |
14 | pub struct ProjectJson { | 14 | pub 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)] | ||
22 | pub 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)] |
@@ -35,12 +27,13 @@ pub struct Crate { | |||
35 | pub(crate) out_dir: Option<AbsPathBuf>, | 27 | pub(crate) out_dir: Option<AbsPathBuf>, |
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 | ||
40 | impl ProjectJson { | 34 | impl 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 |
@@ -79,6 +83,8 @@ impl ProjectJson { | |||
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)] |
90 | pub struct ProjectJsonData { | 96 | pub struct ProjectJsonData { |
91 | roots: Vec<PathBuf>, | ||
92 | crates: Vec<CrateData>, | 97 | crates: Vec<CrateData>, |
93 | } | 98 | } |
94 | 99 | ||
@@ -103,6 +108,7 @@ struct CrateData { | |||
103 | out_dir: Option<PathBuf>, | 108 | out_dir: Option<PathBuf>, |
104 | proc_macro_dylib_path: Option<PathBuf>, | 109 | proc_macro_dylib_path: Option<PathBuf>, |
105 | is_workspace_member: Option<bool>, | 110 | is_workspace_member: Option<bool>, |
111 | source: Option<CrateSource>, | ||
106 | } | 112 | } |
107 | 113 | ||
108 | #[derive(Deserialize)] | 114 | #[derive(Deserialize)] |
@@ -132,6 +138,12 @@ struct DepData { | |||
132 | name: CrateName, | 138 | name: CrateName, |
133 | } | 139 | } |
134 | 140 | ||
141 | #[derive(Deserialize)] | ||
142 | struct CrateSource { | ||
143 | include_dirs: Vec<PathBuf>, | ||
144 | exclude_dirs: Vec<PathBuf>, | ||
145 | } | ||
146 | |||
135 | fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error> | 147 | fn deserialize_crate_name<'de, D>(de: D) -> Result<CrateName, D::Error> |
136 | where | 148 | where |
137 | D: de::Deserializer<'de>, | 149 | D: de::Deserializer<'de>, |