Skip to content

Commit e70cf70

Browse files
bors[bot]woody77
andauthored
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 <[email protected]>
2 parents 59f9fc4 + 38f1ce6 commit e70cf70

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

crates/project_model/src/project_json.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::cfg_flag::CfgFlag;
1313
#[derive(Clone, Debug, Eq, PartialEq)]
1414
pub struct ProjectJson {
1515
pub(crate) sysroot_src: Option<AbsPathBuf>,
16-
project_root: Option<AbsPathBuf>,
16+
project_root: AbsPathBuf,
1717
crates: Vec<Crate>,
1818
}
1919

@@ -34,10 +34,17 @@ pub struct Crate {
3434
}
3535

3636
impl ProjectJson {
37+
/// Create a new ProjectJson instance.
38+
///
39+
/// # Arguments
40+
///
41+
/// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
42+
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
43+
/// configuration.
3744
pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
3845
ProjectJson {
3946
sysroot_src: data.sysroot_src.map(|it| base.join(it)),
40-
project_root: base.parent().map(AbsPath::to_path_buf),
47+
project_root: base.to_path_buf(),
4148
crates: data
4249
.crates
4350
.into_iter()
@@ -85,17 +92,17 @@ impl ProjectJson {
8592
.collect::<Vec<_>>(),
8693
}
8794
}
95+
/// Returns the number of crates in the project.
8896
pub fn n_crates(&self) -> usize {
8997
self.crates.len()
9098
}
99+
/// Returns an iterator over the crates in the project.
91100
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
92101
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
93102
}
94-
pub fn path(&self) -> Option<&AbsPath> {
95-
match &self.project_root {
96-
Some(p) => Some(p.as_path()),
97-
None => None,
98-
}
103+
/// Returns the path to the project's root folder.
104+
pub fn path(&self) -> &AbsPath {
105+
&self.project_root
99106
}
100107
}
101108

crates/rust-analyzer/src/reload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl GlobalState {
252252
// Enable flychecks for json projects if a custom flycheck command was supplied
253253
// in the workspace configuration.
254254
match config {
255-
FlycheckConfig::CustomCommand { .. } => project.path(),
255+
FlycheckConfig::CustomCommand { .. } => Some(project.path()),
256256
_ => None,
257257
}
258258
}

0 commit comments

Comments
 (0)