aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index d5f82f17a..a99612690 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -58,24 +58,24 @@ impl PackageRoot {
58} 58}
59 59
60#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] 60#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
61pub enum ProjectRoot { 61pub enum ProjectManifest {
62 ProjectJson(PathBuf), 62 ProjectJson(PathBuf),
63 CargoToml(PathBuf), 63 CargoToml(PathBuf),
64} 64}
65 65
66impl ProjectRoot { 66impl ProjectManifest {
67 pub fn from_manifest_file(path: PathBuf) -> Result<ProjectRoot> { 67 pub fn from_manifest_file(path: PathBuf) -> Result<ProjectManifest> {
68 if path.ends_with("rust-project.json") { 68 if path.ends_with("rust-project.json") {
69 return Ok(ProjectRoot::ProjectJson(path)); 69 return Ok(ProjectManifest::ProjectJson(path));
70 } 70 }
71 if path.ends_with("Cargo.toml") { 71 if path.ends_with("Cargo.toml") {
72 return Ok(ProjectRoot::CargoToml(path)); 72 return Ok(ProjectManifest::CargoToml(path));
73 } 73 }
74 bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display()) 74 bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display())
75 } 75 }
76 76
77 pub fn discover_single(path: &Path) -> Result<ProjectRoot> { 77 pub fn discover_single(path: &Path) -> Result<ProjectManifest> {
78 let mut candidates = ProjectRoot::discover(path)?; 78 let mut candidates = ProjectManifest::discover(path)?;
79 let res = match candidates.pop() { 79 let res = match candidates.pop() {
80 None => bail!("no projects"), 80 None => bail!("no projects"),
81 Some(it) => it, 81 Some(it) => it,
@@ -87,12 +87,12 @@ impl ProjectRoot {
87 Ok(res) 87 Ok(res)
88 } 88 }
89 89
90 pub fn discover(path: &Path) -> io::Result<Vec<ProjectRoot>> { 90 pub fn discover(path: &Path) -> io::Result<Vec<ProjectManifest>> {
91 if let Some(project_json) = find_in_parent_dirs(path, "rust-project.json") { 91 if let Some(project_json) = find_in_parent_dirs(path, "rust-project.json") {
92 return Ok(vec![ProjectRoot::ProjectJson(project_json)]); 92 return Ok(vec![ProjectManifest::ProjectJson(project_json)]);
93 } 93 }
94 return find_cargo_toml(path) 94 return find_cargo_toml(path)
95 .map(|paths| paths.into_iter().map(ProjectRoot::CargoToml).collect()); 95 .map(|paths| paths.into_iter().map(ProjectManifest::CargoToml).collect());
96 96
97 fn find_cargo_toml(path: &Path) -> io::Result<Vec<PathBuf>> { 97 fn find_cargo_toml(path: &Path) -> io::Result<Vec<PathBuf>> {
98 match find_in_parent_dirs(path, "Cargo.toml") { 98 match find_in_parent_dirs(path, "Cargo.toml") {
@@ -129,10 +129,10 @@ impl ProjectRoot {
129 } 129 }
130 } 130 }
131 131
132 pub fn discover_all(paths: &[impl AsRef<Path>]) -> Vec<ProjectRoot> { 132 pub fn discover_all(paths: &[impl AsRef<Path>]) -> Vec<ProjectManifest> {
133 let mut res = paths 133 let mut res = paths
134 .iter() 134 .iter()
135 .filter_map(|it| ProjectRoot::discover(it.as_ref()).ok()) 135 .filter_map(|it| ProjectManifest::discover(it.as_ref()).ok())
136 .flatten() 136 .flatten()
137 .collect::<FxHashSet<_>>() 137 .collect::<FxHashSet<_>>()
138 .into_iter() 138 .into_iter()
@@ -144,12 +144,12 @@ impl ProjectRoot {
144 144
145impl ProjectWorkspace { 145impl ProjectWorkspace {
146 pub fn load( 146 pub fn load(
147 root: ProjectRoot, 147 root: ProjectManifest,
148 cargo_features: &CargoConfig, 148 cargo_features: &CargoConfig,
149 with_sysroot: bool, 149 with_sysroot: bool,
150 ) -> Result<ProjectWorkspace> { 150 ) -> Result<ProjectWorkspace> {
151 let res = match root { 151 let res = match root {
152 ProjectRoot::ProjectJson(project_json) => { 152 ProjectManifest::ProjectJson(project_json) => {
153 let file = File::open(&project_json).with_context(|| { 153 let file = File::open(&project_json).with_context(|| {
154 format!("Failed to open json file {}", project_json.display()) 154 format!("Failed to open json file {}", project_json.display())
155 })?; 155 })?;
@@ -160,7 +160,7 @@ impl ProjectWorkspace {
160 })?, 160 })?,
161 } 161 }
162 } 162 }
163 ProjectRoot::CargoToml(cargo_toml) => { 163 ProjectManifest::CargoToml(cargo_toml) => {
164 let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml, cargo_features) 164 let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml, cargo_features)
165 .with_context(|| { 165 .with_context(|| {
166 format!( 166 format!(