diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index b9c5424bf..cf46048e5 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -37,28 +37,10 @@ pub enum ProjectWorkspace { | |||
37 | /// the current workspace. | 37 | /// the current workspace. |
38 | #[derive(Debug, Clone)] | 38 | #[derive(Debug, Clone)] |
39 | pub struct PackageRoot { | 39 | pub struct PackageRoot { |
40 | /// Path to the root folder | ||
41 | path: AbsPathBuf, | ||
42 | /// Is a member of the current workspace | 40 | /// Is a member of the current workspace |
43 | is_member: bool, | 41 | pub is_member: bool, |
44 | out_dir: Option<AbsPathBuf>, | 42 | pub include: Vec<AbsPathBuf>, |
45 | } | 43 | pub exclude: Vec<AbsPathBuf>, |
46 | impl PackageRoot { | ||
47 | pub fn new_member(path: AbsPathBuf) -> PackageRoot { | ||
48 | Self { path, is_member: true, out_dir: None } | ||
49 | } | ||
50 | pub fn new_non_member(path: AbsPathBuf) -> PackageRoot { | ||
51 | Self { path, is_member: false, out_dir: None } | ||
52 | } | ||
53 | pub fn path(&self) -> &AbsPath { | ||
54 | &self.path | ||
55 | } | ||
56 | pub fn out_dir(&self) -> Option<&AbsPath> { | ||
57 | self.out_dir.as_deref() | ||
58 | } | ||
59 | pub fn is_member(&self) -> bool { | ||
60 | self.is_member | ||
61 | } | ||
62 | } | 44 | } |
63 | 45 | ||
64 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] | 46 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] |
@@ -195,18 +177,38 @@ impl ProjectWorkspace { | |||
195 | /// the root is a member of the current workspace | 177 | /// the root is a member of the current workspace |
196 | pub fn to_roots(&self) -> Vec<PackageRoot> { | 178 | pub fn to_roots(&self) -> Vec<PackageRoot> { |
197 | match self { | 179 | match self { |
198 | ProjectWorkspace::Json { project } => { | 180 | ProjectWorkspace::Json { project } => project |
199 | project.roots.iter().map(|r| PackageRoot::new_member(r.path.clone())).collect() | 181 | .roots |
200 | } | 182 | .iter() |
183 | .map(|r| { | ||
184 | let path = r.path.clone(); | ||
185 | let include = vec![path]; | ||
186 | PackageRoot { is_member: true, include, exclude: Vec::new() } | ||
187 | }) | ||
188 | .collect(), | ||
201 | ProjectWorkspace::Cargo { cargo, sysroot } => cargo | 189 | ProjectWorkspace::Cargo { cargo, sysroot } => cargo |
202 | .packages() | 190 | .packages() |
203 | .map(|pkg| PackageRoot { | 191 | .map(|pkg| { |
204 | path: cargo[pkg].root().to_path_buf(), | 192 | let is_member = cargo[pkg].is_member; |
205 | is_member: cargo[pkg].is_member, | 193 | let pkg_root = cargo[pkg].root().to_path_buf(); |
206 | out_dir: cargo[pkg].out_dir.clone(), | 194 | |
195 | let mut include = vec![pkg_root.clone()]; | ||
196 | include.extend(cargo[pkg].out_dir.clone()); | ||
197 | |||
198 | let mut exclude = vec![pkg_root.join(".git")]; | ||
199 | if is_member { | ||
200 | exclude.push(pkg_root.join("target")); | ||
201 | } else { | ||
202 | exclude.push(pkg_root.join("tests")); | ||
203 | exclude.push(pkg_root.join("examples")); | ||
204 | exclude.push(pkg_root.join("benches")); | ||
205 | } | ||
206 | PackageRoot { is_member, include, exclude } | ||
207 | }) | 207 | }) |
208 | .chain(sysroot.crates().map(|krate| { | 208 | .chain(sysroot.crates().map(|krate| PackageRoot { |
209 | PackageRoot::new_non_member(sysroot[krate].root_dir().to_path_buf()) | 209 | is_member: false, |
210 | include: vec![sysroot[krate].root_dir().to_path_buf()], | ||
211 | exclude: Vec::new(), | ||
210 | })) | 212 | })) |
211 | .collect(), | 213 | .collect(), |
212 | } | 214 | } |