aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-14 18:26:07 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-14 18:26:07 +0100
commit88be6f32172813f53dae60d73c9f5deb0c3fb29f (patch)
tree0b5f8f793929f651dfe332e0f5545b938ff5189f /crates/ra_project_model/src
parent5d35f284f5ac70cde5d758e7c63a38eae0fb0b55 (diff)
parentc2dfc8a229c0a18dff08d5ce7e6836c91648eee5 (diff)
Merge #1137
1137: Adds support for multiple editor workspaces on initialization r=matklad a=jrvidal OK, so this "simple hack" turned out to be way more contrived than I expected :joy: ### What works This patch only handles multi-folder editor workspaces _on initialization_. * I've found that modifying the layout of a workspace in VSCode just reloads the extension, so this hack should be enough for now. * Not sure about how emacs-lsp behaves, but we fallback gracefully to the mono-folder workspace, so it should be fine. ### What doesn't work * [x] `cargo watch` can only watch a single root folder with a `Cargo.toml`. I've left this part untouched but we could either warn that it's not supported or launch _multiple_ `cargo-watch` processes. * [x] The `rust-analyzer/runnables` command is not functional, since we don't send the correct `cwd`. * [x] Should we add some happy path test to `heavy_tests`? * [ ] Going from a single `root` to multiple `roots` leaves us with a couple of `n * m` loops that smell a bit. The number of folders in the editor workspace is probably low though. Co-authored-by: Roberto Vidal <[email protected]>
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> {