aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-04-01 00:15:20 +0100
committerveetaha <[email protected]>2020-04-02 19:07:05 +0100
commitb7d5172f69204b6d097d80a39dacad3494a26f5e (patch)
treef6bd3540fb56be4fbcbbd20fae2e6574f39e99ad /crates/ra_project_model/src
parent4b2bf9cf66ecfc0bca0d1405ceb0d6eb923b78e2 (diff)
Simpify workspace handling
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/lib.rs46
1 files changed, 17 insertions, 29 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index dd9c80691..a133243b4 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -58,22 +58,16 @@ pub enum ProjectWorkspace {
58#[derive(Clone)] 58#[derive(Clone)]
59pub struct PackageRoot { 59pub struct PackageRoot {
60 /// Path to the root folder 60 /// Path to the root folder
61 path: PathBuf, 61 pub path: PathBuf,
62 /// Is a member of the current workspace 62 /// Is a member of the current workspace
63 is_member: bool, 63 pub is_member: bool,
64} 64}
65
66impl PackageRoot { 65impl PackageRoot {
67 pub fn new(path: PathBuf, is_member: bool) -> PackageRoot { 66 pub fn new_member(path: PathBuf) -> PackageRoot {
68 PackageRoot { path, is_member } 67 Self { path, is_member: true }
69 }
70
71 pub fn path(&self) -> &PathBuf {
72 &self.path
73 } 68 }
74 69 pub fn new_non_member(path: PathBuf) -> PackageRoot {
75 pub fn is_member(&self) -> bool { 70 Self { path, is_member: false }
76 self.is_member
77 } 71 }
78} 72}
79 73
@@ -130,24 +124,18 @@ impl ProjectWorkspace {
130 pub fn to_roots(&self) -> Vec<PackageRoot> { 124 pub fn to_roots(&self) -> Vec<PackageRoot> {
131 match self { 125 match self {
132 ProjectWorkspace::Json { project } => { 126 ProjectWorkspace::Json { project } => {
133 let mut roots = Vec::with_capacity(project.roots.len()); 127 project.roots.iter().map(|r| PackageRoot::new_member(r.path.clone())).collect()
134 for root in &project.roots {
135 roots.push(PackageRoot::new(root.path.clone(), true));
136 }
137 roots
138 }
139 ProjectWorkspace::Cargo { cargo, sysroot } => {
140 let mut roots = Vec::with_capacity(cargo.packages().len() + sysroot.crates().len());
141 for pkg in cargo.packages() {
142 let root = cargo[pkg].root().to_path_buf();
143 let member = cargo[pkg].is_member;
144 roots.push(PackageRoot::new(root, member));
145 }
146 for krate in sysroot.crates() {
147 roots.push(PackageRoot::new(sysroot[krate].root_dir().to_path_buf(), false))
148 }
149 roots
150 } 128 }
129 ProjectWorkspace::Cargo { cargo, sysroot } => cargo
130 .packages()
131 .map(|pkg| PackageRoot {
132 path: cargo[pkg].root().to_path_buf(),
133 is_member: cargo[pkg].is_member,
134 })
135 .chain(sysroot.crates().map(|krate| {
136 PackageRoot::new_non_member(sysroot[krate].root_dir().to_path_buf())
137 }))
138 .collect(),
151 } 139 }
152 } 140 }
153 141