mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Simplify Sysroot
This commit is contained in:
parent
516fe293a8
commit
fc230b943b
2 changed files with 20 additions and 22 deletions
|
@ -143,7 +143,7 @@ impl ProjectWorkspace {
|
|||
roots.push(PackageRoot::new(root, member));
|
||||
}
|
||||
for krate in sysroot.crates() {
|
||||
roots.push(PackageRoot::new(krate.root_dir(&sysroot).to_path_buf(), false))
|
||||
roots.push(PackageRoot::new(sysroot[krate].root_dir().to_path_buf(), false))
|
||||
}
|
||||
roots
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ impl ProjectWorkspace {
|
|||
ProjectWorkspace::Cargo { cargo, sysroot } => {
|
||||
let mut sysroot_crates = FxHashMap::default();
|
||||
for krate in sysroot.crates() {
|
||||
if let Some(file_id) = load(krate.root(&sysroot)) {
|
||||
if let Some(file_id) = load(&sysroot[krate].root) {
|
||||
// Crates from sysroot have `cfg(test)` disabled
|
||||
let cfg_options = {
|
||||
let mut opts = default_cfg_options.clone();
|
||||
|
@ -274,7 +274,7 @@ impl ProjectWorkspace {
|
|||
file_id,
|
||||
Edition::Edition2018,
|
||||
Some(
|
||||
CrateName::new(krate.name(&sysroot))
|
||||
CrateName::new(&sysroot[krate].name)
|
||||
.expect("Sysroot crate names should not contain dashes"),
|
||||
),
|
||||
cfg_options,
|
||||
|
@ -285,8 +285,8 @@ impl ProjectWorkspace {
|
|||
}
|
||||
}
|
||||
for from in sysroot.crates() {
|
||||
for to in from.deps(&sysroot) {
|
||||
let name = to.name(&sysroot);
|
||||
for &to in sysroot[from].deps.iter() {
|
||||
let name = &sysroot[to].name;
|
||||
if let (Some(&from), Some(&to)) =
|
||||
(sysroot_crates.get(&from), sysroot_crates.get(&to))
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::{
|
||||
env,
|
||||
env, ops,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Output},
|
||||
};
|
||||
|
@ -19,10 +19,17 @@ pub struct SysrootCrate(RawId);
|
|||
impl_arena_id!(SysrootCrate);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct SysrootCrateData {
|
||||
name: String,
|
||||
root: PathBuf,
|
||||
deps: Vec<SysrootCrate>,
|
||||
pub struct SysrootCrateData {
|
||||
pub name: String,
|
||||
pub root: PathBuf,
|
||||
pub deps: Vec<SysrootCrate>,
|
||||
}
|
||||
|
||||
impl ops::Index<SysrootCrate> for Sysroot {
|
||||
type Output = SysrootCrateData;
|
||||
fn index(&self, index: SysrootCrate) -> &SysrootCrateData {
|
||||
&self.crates[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl Sysroot {
|
||||
|
@ -129,18 +136,9 @@ fn get_or_install_rust_src(cargo_toml: &Path) -> Result<PathBuf> {
|
|||
Ok(src_path)
|
||||
}
|
||||
|
||||
impl SysrootCrate {
|
||||
pub fn name(self, sysroot: &Sysroot) -> &str {
|
||||
&sysroot.crates[self].name
|
||||
}
|
||||
pub fn root(self, sysroot: &Sysroot) -> &Path {
|
||||
sysroot.crates[self].root.as_path()
|
||||
}
|
||||
pub fn root_dir(self, sysroot: &Sysroot) -> &Path {
|
||||
self.root(sysroot).parent().unwrap()
|
||||
}
|
||||
pub fn deps<'a>(self, sysroot: &'a Sysroot) -> impl Iterator<Item = SysrootCrate> + 'a {
|
||||
sysroot.crates[self].deps.iter().copied()
|
||||
impl SysrootCrateData {
|
||||
pub fn root_dir(&self) -> &Path {
|
||||
self.root.parent().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue