From 39a2bc5e3cd86876eef6f3a96bef188f88e85114 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 21 Jul 2020 12:52:51 +0200 Subject: Expose package roots more directly --- crates/ra_project_model/src/lib.rs | 62 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'crates/ra_project_model') 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 { /// the current workspace. #[derive(Debug, Clone)] pub struct PackageRoot { - /// Path to the root folder - path: AbsPathBuf, /// Is a member of the current workspace - is_member: bool, - out_dir: Option, -} -impl PackageRoot { - pub fn new_member(path: AbsPathBuf) -> PackageRoot { - Self { path, is_member: true, out_dir: None } - } - pub fn new_non_member(path: AbsPathBuf) -> PackageRoot { - Self { path, is_member: false, out_dir: None } - } - pub fn path(&self) -> &AbsPath { - &self.path - } - pub fn out_dir(&self) -> Option<&AbsPath> { - self.out_dir.as_deref() - } - pub fn is_member(&self) -> bool { - self.is_member - } + pub is_member: bool, + pub include: Vec, + pub exclude: Vec, } #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] @@ -195,18 +177,38 @@ impl ProjectWorkspace { /// the root is a member of the current workspace pub fn to_roots(&self) -> Vec { match self { - ProjectWorkspace::Json { project } => { - project.roots.iter().map(|r| PackageRoot::new_member(r.path.clone())).collect() - } + ProjectWorkspace::Json { project } => project + .roots + .iter() + .map(|r| { + let path = r.path.clone(); + let include = vec![path]; + PackageRoot { is_member: true, include, exclude: Vec::new() } + }) + .collect(), ProjectWorkspace::Cargo { cargo, sysroot } => cargo .packages() - .map(|pkg| PackageRoot { - path: cargo[pkg].root().to_path_buf(), - is_member: cargo[pkg].is_member, - out_dir: cargo[pkg].out_dir.clone(), + .map(|pkg| { + let is_member = cargo[pkg].is_member; + let pkg_root = cargo[pkg].root().to_path_buf(); + + let mut include = vec![pkg_root.clone()]; + include.extend(cargo[pkg].out_dir.clone()); + + let mut exclude = vec![pkg_root.join(".git")]; + if is_member { + exclude.push(pkg_root.join("target")); + } else { + exclude.push(pkg_root.join("tests")); + exclude.push(pkg_root.join("examples")); + exclude.push(pkg_root.join("benches")); + } + PackageRoot { is_member, include, exclude } }) - .chain(sysroot.crates().map(|krate| { - PackageRoot::new_non_member(sysroot[krate].root_dir().to_path_buf()) + .chain(sysroot.crates().map(|krate| PackageRoot { + is_member: false, + include: vec![sysroot[krate].root_dir().to_path_buf()], + exclude: Vec::new(), })) .collect(), } -- cgit v1.2.3