From 7c7cfc5f04c51ed1e31b6a3091efc3941b3383c2 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Sat, 13 Apr 2019 19:45:21 +0200 Subject: Sends cwd info for runnables and code lenses --- crates/ra_project_model/src/cargo_workspace.rs | 3 ++- crates/ra_project_model/src/lib.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'crates/ra_project_model/src') 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; pub struct CargoWorkspace { packages: Arena, targets: Arena, + pub(crate) workspace_root: PathBuf, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -165,7 +166,7 @@ impl CargoWorkspace { } } - Ok(CargoWorkspace { packages, targets }) + Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root }) } pub fn packages<'a>(&'a self) -> impl Iterator + '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 { } crate_graph } + + pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> { + match self { + ProjectWorkspace::Cargo { cargo, .. } => { + Some(cargo.workspace_root.as_ref()).filter(|root| path.starts_with(root)) + } + ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots + .iter() + .find(|root| path.starts_with(&root.path)) + .map(|root| root.path.as_ref()), + } + } } fn find_rust_project_json(path: &Path) -> Option { -- cgit v1.2.3