Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/project_json.rs')
-rw-r--r--crates/project-model/src/project_json.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs
index fac6eb8ad3..5bee446f61 100644
--- a/crates/project-model/src/project_json.rs
+++ b/crates/project-model/src/project_json.rs
@@ -56,6 +56,7 @@ use serde::{de, Deserialize, Serialize};
use span::Edition;
use crate::cfg::CfgFlag;
+use crate::ManifestPath;
/// Roots and crates that compose this Rust project.
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -65,6 +66,7 @@ pub struct ProjectJson {
/// e.g. `path/to/sysroot/lib/rustlib/src/rust`
pub(crate) sysroot_src: Option<AbsPathBuf>,
project_root: AbsPathBuf,
+ manifest: Option<ManifestPath>,
crates: Vec<Crate>,
}
@@ -96,12 +98,17 @@ impl ProjectJson {
/// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
/// configuration.
- pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
+ pub fn new(
+ manifest: Option<ManifestPath>,
+ base: &AbsPath,
+ data: ProjectJsonData,
+ ) -> ProjectJson {
let absolutize_on_base = |p| base.absolutize(p);
ProjectJson {
sysroot: data.sysroot.map(absolutize_on_base),
sysroot_src: data.sysroot_src.map(absolutize_on_base),
project_root: base.to_path_buf(),
+ manifest,
crates: data
.crates
.into_iter()
@@ -159,6 +166,11 @@ impl ProjectJson {
pub fn path(&self) -> &AbsPath {
&self.project_root
}
+
+ /// Returns the path to the project's manifest or root folder, if no manifest exists.
+ pub fn manifest_or_root(&self) -> &AbsPath {
+ self.manifest.as_ref().map_or(&self.project_root, |manifest| manifest.as_ref())
+ }
}
#[derive(Serialize, Deserialize, Debug, Clone)]