mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Merge #6018
6018: Correct project_root path for ProjectJson. r=jonas-schievink a=woody77 It was already the folder containing the rust-project.json file, not the file itself. This also removes the Option-ness of it, since it's now an infallible operation to set the member value. Co-authored-by: Aaron Wood <aaronwood@google.com>
This commit is contained in:
commit
e70cf706bb
2 changed files with 15 additions and 8 deletions
|
@ -13,7 +13,7 @@ use crate::cfg_flag::CfgFlag;
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct ProjectJson {
|
pub struct ProjectJson {
|
||||||
pub(crate) sysroot_src: Option<AbsPathBuf>,
|
pub(crate) sysroot_src: Option<AbsPathBuf>,
|
||||||
project_root: Option<AbsPathBuf>,
|
project_root: AbsPathBuf,
|
||||||
crates: Vec<Crate>,
|
crates: Vec<Crate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,10 +34,17 @@ pub struct Crate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProjectJson {
|
impl ProjectJson {
|
||||||
|
/// Create a new ProjectJson instance.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `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(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
|
||||||
ProjectJson {
|
ProjectJson {
|
||||||
sysroot_src: data.sysroot_src.map(|it| base.join(it)),
|
sysroot_src: data.sysroot_src.map(|it| base.join(it)),
|
||||||
project_root: base.parent().map(AbsPath::to_path_buf),
|
project_root: base.to_path_buf(),
|
||||||
crates: data
|
crates: data
|
||||||
.crates
|
.crates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -85,17 +92,17 @@ impl ProjectJson {
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Returns the number of crates in the project.
|
||||||
pub fn n_crates(&self) -> usize {
|
pub fn n_crates(&self) -> usize {
|
||||||
self.crates.len()
|
self.crates.len()
|
||||||
}
|
}
|
||||||
|
/// Returns an iterator over the crates in the project.
|
||||||
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
|
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
|
||||||
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
|
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
|
||||||
}
|
}
|
||||||
pub fn path(&self) -> Option<&AbsPath> {
|
/// Returns the path to the project's root folder.
|
||||||
match &self.project_root {
|
pub fn path(&self) -> &AbsPath {
|
||||||
Some(p) => Some(p.as_path()),
|
&self.project_root
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ impl GlobalState {
|
||||||
// Enable flychecks for json projects if a custom flycheck command was supplied
|
// Enable flychecks for json projects if a custom flycheck command was supplied
|
||||||
// in the workspace configuration.
|
// in the workspace configuration.
|
||||||
match config {
|
match config {
|
||||||
FlycheckConfig::CustomCommand { .. } => project.path(),
|
FlycheckConfig::CustomCommand { .. } => Some(project.path()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue