diff options
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 10 | ||||
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 32 |
2 files changed, 20 insertions, 22 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 3c294e065..b500a74fb 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -143,7 +143,7 @@ impl ProjectWorkspace { | |||
143 | roots.push(PackageRoot::new(root, member)); | 143 | roots.push(PackageRoot::new(root, member)); |
144 | } | 144 | } |
145 | for krate in sysroot.crates() { | 145 | for krate in sysroot.crates() { |
146 | roots.push(PackageRoot::new(krate.root_dir(&sysroot).to_path_buf(), false)) | 146 | roots.push(PackageRoot::new(sysroot[krate].root_dir().to_path_buf(), false)) |
147 | } | 147 | } |
148 | roots | 148 | roots |
149 | } | 149 | } |
@@ -260,7 +260,7 @@ impl ProjectWorkspace { | |||
260 | ProjectWorkspace::Cargo { cargo, sysroot } => { | 260 | ProjectWorkspace::Cargo { cargo, sysroot } => { |
261 | let mut sysroot_crates = FxHashMap::default(); | 261 | let mut sysroot_crates = FxHashMap::default(); |
262 | for krate in sysroot.crates() { | 262 | for krate in sysroot.crates() { |
263 | if let Some(file_id) = load(krate.root(&sysroot)) { | 263 | if let Some(file_id) = load(&sysroot[krate].root) { |
264 | // Crates from sysroot have `cfg(test)` disabled | 264 | // Crates from sysroot have `cfg(test)` disabled |
265 | let cfg_options = { | 265 | let cfg_options = { |
266 | let mut opts = default_cfg_options.clone(); | 266 | let mut opts = default_cfg_options.clone(); |
@@ -274,7 +274,7 @@ impl ProjectWorkspace { | |||
274 | file_id, | 274 | file_id, |
275 | Edition::Edition2018, | 275 | Edition::Edition2018, |
276 | Some( | 276 | Some( |
277 | CrateName::new(krate.name(&sysroot)) | 277 | CrateName::new(&sysroot[krate].name) |
278 | .expect("Sysroot crate names should not contain dashes"), | 278 | .expect("Sysroot crate names should not contain dashes"), |
279 | ), | 279 | ), |
280 | cfg_options, | 280 | cfg_options, |
@@ -285,8 +285,8 @@ impl ProjectWorkspace { | |||
285 | } | 285 | } |
286 | } | 286 | } |
287 | for from in sysroot.crates() { | 287 | for from in sysroot.crates() { |
288 | for to in from.deps(&sysroot) { | 288 | for &to in sysroot[from].deps.iter() { |
289 | let name = to.name(&sysroot); | 289 | let name = &sysroot[to].name; |
290 | if let (Some(&from), Some(&to)) = | 290 | if let (Some(&from), Some(&to)) = |
291 | (sysroot_crates.get(&from), sysroot_crates.get(&to)) | 291 | (sysroot_crates.get(&from), sysroot_crates.get(&to)) |
292 | { | 292 | { |
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index c51957c1f..4ac4fa14d 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
4 | use std::{ | 4 | use std::{ |
5 | env, | 5 | env, ops, |
6 | path::{Path, PathBuf}, | 6 | path::{Path, PathBuf}, |
7 | process::{Command, Output}, | 7 | process::{Command, Output}, |
8 | }; | 8 | }; |
@@ -19,10 +19,17 @@ pub struct SysrootCrate(RawId); | |||
19 | impl_arena_id!(SysrootCrate); | 19 | impl_arena_id!(SysrootCrate); |
20 | 20 | ||
21 | #[derive(Debug, Clone)] | 21 | #[derive(Debug, Clone)] |
22 | struct SysrootCrateData { | 22 | pub struct SysrootCrateData { |
23 | name: String, | 23 | pub name: String, |
24 | root: PathBuf, | 24 | pub root: PathBuf, |
25 | deps: Vec<SysrootCrate>, | 25 | pub deps: Vec<SysrootCrate>, |
26 | } | ||
27 | |||
28 | impl ops::Index<SysrootCrate> for Sysroot { | ||
29 | type Output = SysrootCrateData; | ||
30 | fn index(&self, index: SysrootCrate) -> &SysrootCrateData { | ||
31 | &self.crates[index] | ||
32 | } | ||
26 | } | 33 | } |
27 | 34 | ||
28 | impl Sysroot { | 35 | impl Sysroot { |
@@ -129,18 +136,9 @@ fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> { | |||
129 | Ok(src_path) | 136 | Ok(src_path) |
130 | } | 137 | } |
131 | 138 | ||
132 | impl SysrootCrate { | 139 | impl SysrootCrateData { |
133 | pub fn name(self, sysroot: &Sysroot) -> &str { | 140 | pub fn root_dir(&self) -> &Path { |
134 | &sysroot.crates[self].name | 141 | self.root.parent().unwrap() |
135 | } | ||
136 | pub fn root(self, sysroot: &Sysroot) -> &Path { | ||
137 | sysroot.crates[self].root.as_path() | ||
138 | } | ||
139 | pub fn root_dir(self, sysroot: &Sysroot) -> &Path { | ||
140 | self.root(sysroot).parent().unwrap() | ||
141 | } | ||
142 | pub fn deps<'a>(self, sysroot: &'a Sysroot) -> impl Iterator<Item = SysrootCrate> + 'a { | ||
143 | sysroot.crates[self].deps.iter().copied() | ||
144 | } | 142 | } |
145 | } | 143 | } |
146 | 144 | ||