mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Expose package roots more directly
This commit is contained in:
parent
818aeb8a24
commit
39a2bc5e3c
3 changed files with 51 additions and 55 deletions
|
@ -37,28 +37,10 @@ pub enum ProjectWorkspace {
|
|||
/// the current workspace.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PackageRoot {
|
||||
/// Path to the root folder
|
||||
path: AbsPathBuf,
|
||||
/// Is a member of the current workspace
|
||||
is_member: bool,
|
||||
out_dir: Option<AbsPathBuf>,
|
||||
}
|
||||
impl PackageRoot {
|
||||
pub fn new_member(path: AbsPathBuf) -> PackageRoot {
|
||||
Self { path, is_member: true, out_dir: None }
|
||||
}
|
||||
pub fn new_non_member(path: AbsPathBuf) -> PackageRoot {
|
||||
Self { path, is_member: false, out_dir: None }
|
||||
}
|
||||
pub fn path(&self) -> &AbsPath {
|
||||
&self.path
|
||||
}
|
||||
pub fn out_dir(&self) -> Option<&AbsPath> {
|
||||
self.out_dir.as_deref()
|
||||
}
|
||||
pub fn is_member(&self) -> bool {
|
||||
self.is_member
|
||||
}
|
||||
pub is_member: bool,
|
||||
pub include: Vec<AbsPathBuf>,
|
||||
pub exclude: Vec<AbsPathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
||||
|
@ -195,18 +177,38 @@ impl ProjectWorkspace {
|
|||
/// the root is a member of the current workspace
|
||||
pub fn to_roots(&self) -> Vec<PackageRoot> {
|
||||
match self {
|
||||
ProjectWorkspace::Json { project } => {
|
||||
project.roots.iter().map(|r| PackageRoot::new_member(r.path.clone())).collect()
|
||||
}
|
||||
ProjectWorkspace::Json { project } => project
|
||||
.roots
|
||||
.iter()
|
||||
.map(|r| {
|
||||
let path = r.path.clone();
|
||||
let include = vec![path];
|
||||
PackageRoot { is_member: true, include, exclude: Vec::new() }
|
||||
})
|
||||
.collect(),
|
||||
ProjectWorkspace::Cargo { cargo, sysroot } => cargo
|
||||
.packages()
|
||||
.map(|pkg| PackageRoot {
|
||||
path: cargo[pkg].root().to_path_buf(),
|
||||
is_member: cargo[pkg].is_member,
|
||||
out_dir: cargo[pkg].out_dir.clone(),
|
||||
.map(|pkg| {
|
||||
let is_member = cargo[pkg].is_member;
|
||||
let pkg_root = cargo[pkg].root().to_path_buf();
|
||||
|
||||
let mut include = vec![pkg_root.clone()];
|
||||
include.extend(cargo[pkg].out_dir.clone());
|
||||
|
||||
let mut exclude = vec![pkg_root.join(".git")];
|
||||
if is_member {
|
||||
exclude.push(pkg_root.join("target"));
|
||||
} else {
|
||||
exclude.push(pkg_root.join("tests"));
|
||||
exclude.push(pkg_root.join("examples"));
|
||||
exclude.push(pkg_root.join("benches"));
|
||||
}
|
||||
PackageRoot { is_member, include, exclude }
|
||||
})
|
||||
.chain(sysroot.crates().map(|krate| {
|
||||
PackageRoot::new_non_member(sysroot[krate].root_dir().to_path_buf())
|
||||
.chain(sysroot.crates().map(|krate| PackageRoot {
|
||||
is_member: false,
|
||||
include: vec![sysroot[krate].root_dir().to_path_buf()],
|
||||
exclude: Vec::new(),
|
||||
}))
|
||||
.collect(),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue