diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index 545f254aae..1ab1221cba 100644 --- a/crates/project_model/src/project_json.rs +++ b/crates/project_model/src/project_json.rs @@ -13,7 +13,7 @@ use crate::cfg_flag::CfgFlag; #[derive(Clone, Debug, Eq, PartialEq)] pub struct ProjectJson { pub(crate) sysroot_src: Option, - project_root: Option, + project_root: AbsPathBuf, crates: Vec, } @@ -37,7 +37,7 @@ impl ProjectJson { pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { ProjectJson { 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 .into_iter() @@ -91,11 +91,8 @@ impl ProjectJson { pub fn crates(&self) -> impl Iterator + '_ { self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) } - pub fn path(&self) -> Option<&AbsPath> { - match &self.project_root { - Some(p) => Some(p.as_path()), - None => None, - } + pub fn path(&self) -> &AbsPath { + &self.project_root } } diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index b819618cb4..a052f36a71 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -249,7 +249,7 @@ impl GlobalState { // Enable flychecks for json projects if a custom flycheck command was supplied // in the workspace configuration. match config { - FlycheckConfig::CustomCommand { .. } => project.path(), + FlycheckConfig::CustomCommand { .. } => Some(project.path()), _ => None, } }