Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/load-cargo/src/lib.rs')
-rw-r--r--crates/load-cargo/src/lib.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs
index 297e37f1f6..08b6f9ca2b 100644
--- a/crates/load-cargo/src/lib.rs
+++ b/crates/load-cargo/src/lib.rs
@@ -283,6 +283,19 @@ impl ProjectFolders {
}
}
+ // Collect workspace roots not already covered by a local PackageRoot
+ // (e.g. virtual workspaces where no package lives at the workspace root).
+ // We need these to load workspace-root rust-analyzer.toml into a local source root.
+ let uncovered_ws_roots: Vec<AbsPathBuf> = workspaces
+ .iter()
+ .filter_map(|ws| {
+ let ws_root = ws.workspace_root().to_path_buf();
+ let dominated =
+ roots.iter().any(|root| root.is_local && root.include.contains(&ws_root));
+ (!dominated).then_some(ws_root)
+ })
+ .collect();
+
for root in roots.into_iter().filter(|it| !it.include.is_empty()) {
let file_set_roots: Vec<VfsPath> =
root.include.iter().cloned().map(VfsPath::from).collect();
@@ -335,6 +348,20 @@ impl ProjectFolders {
}
}
+ // For virtual workspaces, the workspace root has no local PackageRoot, so
+ // rust-analyzer.toml there would fall into a library source root and be
+ // ignored. Load it explicitly via Entry::Files and register the workspace
+ // root as a local file-set root so the file is classified as local.
+ for ws_root in &uncovered_ws_roots {
+ let ratoml_path = ws_root.join("rust-analyzer.toml");
+ let file_set_roots = vec![VfsPath::from(ws_root.clone())];
+ let entry = vfs::loader::Entry::Files(vec![ratoml_path]);
+ res.watch.push(res.load.len());
+ res.load.push(entry);
+ local_filesets.push(fsc.len() as u64);
+ fsc.add_file_set(file_set_roots);
+ }
+
if let Some(user_config_path) = user_config_dir_path {
let ratoml_path = {
let mut p = user_config_path.to_path_buf();