aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/lib.rs37
1 files changed, 33 insertions, 4 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index c566ec0fb..b27cb55ef 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -32,6 +32,30 @@ pub enum ProjectWorkspace {
32 Json { project: JsonProject }, 32 Json { project: JsonProject },
33} 33}
34 34
35/// `ProjectRoot` describes a workspace root folder.
36/// Which may be an external dependency, or a member of
37/// the current workspace.
38pub struct ProjectRoot {
39 /// Path to the root folder
40 path: PathBuf,
41 /// Is a member of the current workspace
42 is_member: bool,
43}
44
45impl ProjectRoot {
46 fn new(path: PathBuf, is_member: bool) -> ProjectRoot {
47 ProjectRoot { path, is_member }
48 }
49
50 pub fn into_path(self) -> PathBuf {
51 self.path
52 }
53
54 pub fn is_member(&self) -> bool {
55 self.is_member
56 }
57}
58
35impl ProjectWorkspace { 59impl ProjectWorkspace {
36 pub fn discover(path: &Path) -> Result<ProjectWorkspace> { 60 pub fn discover(path: &Path) -> Result<ProjectWorkspace> {
37 match find_rust_project_json(path) { 61 match find_rust_project_json(path) {
@@ -50,12 +74,15 @@ impl ProjectWorkspace {
50 } 74 }
51 } 75 }
52 76
53 pub fn to_roots(&self) -> Vec<PathBuf> { 77 /// Returns the roots for the current ProjectWorkspace
78 /// The return type contains the path and whether or not
79 /// the root is a member of the current workspace
80 pub fn to_roots(&self) -> Vec<ProjectRoot> {
54 match self { 81 match self {
55 ProjectWorkspace::Json { project } => { 82 ProjectWorkspace::Json { project } => {
56 let mut roots = Vec::with_capacity(project.roots.len()); 83 let mut roots = Vec::with_capacity(project.roots.len());
57 for root in &project.roots { 84 for root in &project.roots {
58 roots.push(root.path.clone()); 85 roots.push(ProjectRoot::new(root.path.clone(), true));
59 } 86 }
60 roots 87 roots
61 } 88 }
@@ -63,10 +90,12 @@ impl ProjectWorkspace {
63 let mut roots = 90 let mut roots =
64 Vec::with_capacity(cargo.packages().count() + sysroot.crates().count()); 91 Vec::with_capacity(cargo.packages().count() + sysroot.crates().count());
65 for pkg in cargo.packages() { 92 for pkg in cargo.packages() {
66 roots.push(pkg.root(&cargo).to_path_buf()); 93 let root = pkg.root(&cargo).to_path_buf();
94 let member = pkg.is_member(&cargo);
95 roots.push(ProjectRoot::new(root, member));
67 } 96 }
68 for krate in sysroot.crates() { 97 for krate in sysroot.crates() {
69 roots.push(krate.root_dir(&sysroot).to_path_buf()) 98 roots.push(ProjectRoot::new(krate.root_dir(&sysroot).to_path_buf(), false))
70 } 99 }
71 roots 100 roots
72 } 101 }