aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authorRoberto Vidal <[email protected]>2019-04-13 18:45:21 +0100
committerRoberto Vidal <[email protected]>2019-04-14 09:04:38 +0100
commit7c7cfc5f04c51ed1e31b6a3091efc3941b3383c2 (patch)
tree0bc4d2f3afefb504509676388016da52598fe1dd /crates/ra_project_model/src
parent3507bcb97aaaafba10d55c101bd295f3ab4fed4f (diff)
Sends cwd info for runnables and code lenses
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs3
-rw-r--r--crates/ra_project_model/src/lib.rs12
2 files changed, 14 insertions, 1 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 81cb506b7..71976071f 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -19,6 +19,7 @@ use crate::Result;
19pub struct CargoWorkspace { 19pub struct CargoWorkspace {
20 packages: Arena<Package, PackageData>, 20 packages: Arena<Package, PackageData>,
21 targets: Arena<Target, TargetData>, 21 targets: Arena<Target, TargetData>,
22 pub(crate) workspace_root: PathBuf,
22} 23}
23 24
24#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 25#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -165,7 +166,7 @@ impl CargoWorkspace {
165 } 166 }
166 } 167 }
167 168
168 Ok(CargoWorkspace { packages, targets }) 169 Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root })
169 } 170 }
170 171
171 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a { 172 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a {
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 3bad4f8d3..63eb7041e 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -255,6 +255,18 @@ impl ProjectWorkspace {
255 } 255 }
256 crate_graph 256 crate_graph
257 } 257 }
258
259 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
260 match self {
261 ProjectWorkspace::Cargo { cargo, .. } => {
262 Some(cargo.workspace_root.as_ref()).filter(|root| path.starts_with(root))
263 }
264 ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots
265 .iter()
266 .find(|root| path.starts_with(&root.path))
267 .map(|root| root.path.as_ref()),
268 }
269 }
258} 270}
259 271
260fn find_rust_project_json(path: &Path) -> Option<PathBuf> { 272fn find_rust_project_json(path: &Path) -> Option<PathBuf> {