diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-09-20 20:25:09 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-20 20:25:09 +0100 |
commit | e70cf706bb7c6c07e8c33b537ad24e5333aa5e75 (patch) | |
tree | 99290eb9584d766851b6a07f472ca6256bdb9ee9 /crates | |
parent | 59f9fc4cd10b22b887ae42f12cc886793f0b061b (diff) | |
parent | 38f1ce633d78289c71e0f860d82fda5a62db8f7b (diff) |
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]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/project_model/src/project_json.rs | 21 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 2 |
2 files changed, 15 insertions, 8 deletions
diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index 545f254aa..a6895ecdd 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; | |||
13 | #[derive(Clone, Debug, Eq, PartialEq)] | 13 | #[derive(Clone, Debug, Eq, PartialEq)] |
14 | pub struct ProjectJson { | 14 | pub struct ProjectJson { |
15 | pub(crate) sysroot_src: Option<AbsPathBuf>, | 15 | pub(crate) sysroot_src: Option<AbsPathBuf>, |
16 | project_root: Option<AbsPathBuf>, | 16 | project_root: AbsPathBuf, |
17 | crates: Vec<Crate>, | 17 | crates: Vec<Crate>, |
18 | } | 18 | } |
19 | 19 | ||
@@ -34,10 +34,17 @@ pub struct Crate { | |||
34 | } | 34 | } |
35 | 35 | ||
36 | impl ProjectJson { | 36 | 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. | ||
37 | pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { | 44 | pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { |
38 | ProjectJson { | 45 | ProjectJson { |
39 | sysroot_src: data.sysroot_src.map(|it| base.join(it)), | 46 | 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(), |
41 | crates: data | 48 | crates: data |
42 | .crates | 49 | .crates |
43 | .into_iter() | 50 | .into_iter() |
@@ -85,17 +92,17 @@ impl ProjectJson { | |||
85 | .collect::<Vec<_>>(), | 92 | .collect::<Vec<_>>(), |
86 | } | 93 | } |
87 | } | 94 | } |
95 | /// Returns the number of crates in the project. | ||
88 | pub fn n_crates(&self) -> usize { | 96 | pub fn n_crates(&self) -> usize { |
89 | self.crates.len() | 97 | self.crates.len() |
90 | } | 98 | } |
99 | /// Returns an iterator over the crates in the project. | ||
91 | pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ { | 100 | pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ { |
92 | self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) | 101 | self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) |
93 | } | 102 | } |
94 | pub fn path(&self) -> Option<&AbsPath> { | 103 | /// Returns the path to the project's root folder. |
95 | match &self.project_root { | 104 | pub fn path(&self) -> &AbsPath { |
96 | Some(p) => Some(p.as_path()), | 105 | &self.project_root |
97 | None => None, | ||
98 | } | ||
99 | } | 106 | } |
100 | } | 107 | } |
101 | 108 | ||
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index ae404331d..b070087a4 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -252,7 +252,7 @@ impl GlobalState { | |||
252 | // Enable flychecks for json projects if a custom flycheck command was supplied | 252 | // Enable flychecks for json projects if a custom flycheck command was supplied |
253 | // in the workspace configuration. | 253 | // in the workspace configuration. |
254 | match config { | 254 | match config { |
255 | FlycheckConfig::CustomCommand { .. } => project.path(), | 255 | FlycheckConfig::CustomCommand { .. } => Some(project.path()), |
256 | _ => None, | 256 | _ => None, |
257 | } | 257 | } |
258 | } | 258 | } |