From 2fbb09a73f1f541f69b8591c3c15b44df889d1bc Mon Sep 17 00:00:00 2001 From: Aaron Wood Date: Wed, 16 Sep 2020 12:09:44 -0700 Subject: Correct project_root path for ProjectJson. It was already the folder containing the rust-project.json file, not the file itself. --- crates/project_model/src/project_json.rs | 11 ++++------- crates/rust-analyzer/src/reload.rs | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index 545f254aa..1ab1221cb 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 b819618cb..a052f36a7 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, } } -- cgit v1.2.3 From 38f1ce633d78289c71e0f860d82fda5a62db8f7b Mon Sep 17 00:00:00 2001 From: Aaron Wood Date: Sun, 20 Sep 2020 12:06:12 -0700 Subject: Add rustdoc for ProjectJson methods --- crates/project_model/src/project_json.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'crates') diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index 1ab1221cb..a6895ecdd 100644 --- a/crates/project_model/src/project_json.rs +++ b/crates/project_model/src/project_json.rs @@ -34,6 +34,13 @@ pub struct Crate { } 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 { ProjectJson { sysroot_src: data.sysroot_src.map(|it| base.join(it)), @@ -85,12 +92,15 @@ impl ProjectJson { .collect::>(), } } + /// Returns the number of crates in the project. pub fn n_crates(&self) -> usize { self.crates.len() } + /// Returns an iterator over the crates in the project. pub fn crates(&self) -> impl Iterator + '_ { self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) } + /// Returns the path to the project's root folder. pub fn path(&self) -> &AbsPath { &self.project_root } -- cgit v1.2.3