Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/workspace.rs')
-rw-r--r--crates/project-model/src/workspace.rs45
1 files changed, 26 insertions, 19 deletions
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 988eff9be4..71ddee3091 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -11,8 +11,9 @@ use base_db::{
};
use cfg::{CfgAtom, CfgDiff, CfgOptions};
use intern::{sym, Symbol};
+use itertools::Itertools;
use paths::{AbsPath, AbsPathBuf};
-use rustc_hash::{FxHashMap, FxHashSet};
+use rustc_hash::FxHashMap;
use semver::Version;
use span::{Edition, FileId};
use toolchain::Tool;
@@ -41,7 +42,9 @@ pub type FileLoader<'a> = &'a mut dyn for<'b> FnMut(&'b AbsPath) -> Option<FileI
pub struct PackageRoot {
/// Is from the local filesystem and may be edited
pub is_local: bool,
+ /// Directories to include
pub include: Vec<AbsPathBuf>,
+ /// Directories to exclude
pub exclude: Vec<AbsPathBuf>,
}
@@ -553,17 +556,6 @@ impl ProjectWorkspace {
}
}
- pub fn buildfiles(&self) -> Vec<AbsPathBuf> {
- match &self.kind {
- ProjectWorkspaceKind::Json(project) => project
- .crates()
- .filter_map(|(_, krate)| krate.build.as_ref().map(|build| build.build_file.clone()))
- .map(|build_file| self.workspace_root().join(build_file))
- .collect(),
- _ => vec![],
- }
- }
-
pub fn find_sysroot_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
self.sysroot.discover_proc_macro_srv()
}
@@ -608,15 +600,25 @@ impl ProjectWorkspace {
match &self.kind {
ProjectWorkspaceKind::Json(project) => project
.crates()
- .map(|(_, krate)| PackageRoot {
- is_local: krate.is_workspace_member,
- include: krate.include.clone(),
- exclude: krate.exclude.clone(),
+ .map(|(_, krate)| {
+ let build_files = project
+ .crates()
+ .filter_map(|(_, krate)| {
+ krate.build.as_ref().map(|build| build.build_file.clone())
+ })
+ // FIXME: PackageRoots dont allow specifying files, only directories
+ .filter_map(|build_file| {
+ self.workspace_root().join(build_file).parent().map(ToOwned::to_owned)
+ });
+ PackageRoot {
+ is_local: krate.is_workspace_member,
+ include: krate.include.iter().cloned().chain(build_files).collect(),
+ exclude: krate.exclude.clone(),
+ }
})
- .collect::<FxHashSet<_>>()
- .into_iter()
.chain(mk_sysroot())
- .collect::<Vec<_>>(),
+ .unique()
+ .collect(),
ProjectWorkspaceKind::Cargo {
cargo,
rustc,
@@ -671,6 +673,11 @@ impl ProjectWorkspace {
exclude: Vec::new(),
})
}))
+ .chain(cargo.is_virtual_workspace().then(|| PackageRoot {
+ is_local: true,
+ include: vec![cargo.workspace_root().to_path_buf()],
+ exclude: Vec::new(),
+ }))
.collect()
}
ProjectWorkspaceKind::DetachedFile { file, cargo: cargo_script, .. } => {