Skip to content

Commit 0a14e17

Browse files
committed
Explicitly add buildfiles when constructing ProjectFolders
1 parent 8063b1e commit 0a14e17

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/tools/rust-analyzer/crates/load-cargo/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ impl ProjectFolders {
256256
fsc.add_file_set(file_set_roots)
257257
}
258258

259+
for ws in workspaces.iter() {
260+
let mut file_set_roots: Vec<VfsPath> = vec![];
261+
let mut entries = vec![];
262+
263+
for buildfile in ws.buildfiles() {
264+
file_set_roots.push(VfsPath::from(buildfile.to_owned()));
265+
entries.push(buildfile.to_owned());
266+
}
267+
268+
if !file_set_roots.is_empty() {
269+
let entry = vfs::loader::Entry::Files(entries);
270+
res.watch.push(res.load.len());
271+
res.load.push(entry);
272+
local_filesets.push(fsc.len() as u64);
273+
fsc.add_file_set(file_set_roots)
274+
}
275+
}
276+
259277
if let Some(user_config_path) = user_config_dir_path {
260278
let ratoml_path = {
261279
let mut p = user_config_path.to_path_buf();

src/tools/rust-analyzer/crates/project-model/src/workspace.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,17 @@ impl ProjectWorkspace {
524524
}
525525
}
526526

527+
pub fn buildfiles(&self) -> Vec<AbsPathBuf> {
528+
match &self.kind {
529+
ProjectWorkspaceKind::Json(project) => project
530+
.crates()
531+
.filter_map(|(_, krate)| krate.build.as_ref().map(|build| build.build_file.clone()))
532+
.map(|build_file| self.workspace_root().join(build_file))
533+
.collect(),
534+
_ => vec![],
535+
}
536+
}
537+
527538
pub fn find_sysroot_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
528539
self.sysroot.discover_proc_macro_srv()
529540
}
@@ -568,27 +579,15 @@ impl ProjectWorkspace {
568579
match &self.kind {
569580
ProjectWorkspaceKind::Json(project) => project
570581
.crates()
571-
.map(|(_, krate)| {
572-
// FIXME: PackageRoots dont allow specifying files, only directories
573-
let build_file = krate
574-
.build
575-
.as_ref()
576-
.map(|build| self.workspace_root().join(&build.build_file))
577-
.as_deref()
578-
.and_then(AbsPath::parent)
579-
.map(ToOwned::to_owned);
580-
581-
PackageRoot {
582-
is_local: krate.is_workspace_member,
583-
include: krate
584-
.include
585-
.iter()
586-
.cloned()
587-
.chain(build_file)
588-
.chain(self.extra_includes.iter().cloned())
589-
.collect(),
590-
exclude: krate.exclude.clone(),
591-
}
582+
.map(|(_, krate)| PackageRoot {
583+
is_local: krate.is_workspace_member,
584+
include: krate
585+
.include
586+
.iter()
587+
.cloned()
588+
.chain(self.extra_includes.iter().cloned())
589+
.collect(),
590+
exclude: krate.exclude.clone(),
592591
})
593592
.collect::<FxHashSet<_>>()
594593
.into_iter()

0 commit comments

Comments
 (0)