diff options
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 29 |
1 files changed, 9 insertions, 20 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 { |