diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 46 |
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)] |
59 | pub struct PackageRoot { | 59 | pub 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 | |||
66 | impl PackageRoot { | 65 | impl 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 | ||