Skip to content

Commit dbdf992

Browse files
committed
Auto merge of rust-lang#17661 - alibektas:read_ratoml_on_startup, r=Veykril
minor: Read workspace root ratomls on startup
2 parents 9751cbc + f1e2371 commit dbdf992

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use ide_db::{
1515
};
1616
use itertools::Itertools;
1717
use proc_macro_api::{MacroDylib, ProcMacroServer};
18-
use project_model::{CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace};
18+
use project_model::{
19+
CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
20+
};
1921
use span::Span;
2022
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
2123

@@ -238,15 +240,34 @@ impl ProjectFolders {
238240

239241
// register the workspace manifest as well, note that this currently causes duplicates for
240242
// non-virtual cargo workspaces! We ought to fix that
241-
for manifest in workspaces.iter().filter_map(|ws| ws.manifest().map(ManifestPath::as_ref)) {
242-
let file_set_roots: Vec<VfsPath> = vec![VfsPath::from(manifest.to_owned())];
243+
for ws in workspaces.iter() {
244+
let mut file_set_roots: Vec<VfsPath> = vec![];
245+
let mut entries = vec![];
243246

244-
let entry = vfs::loader::Entry::Files(vec![manifest.to_owned()]);
247+
if let Some(manifest) = ws.manifest().map(ManifestPath::as_ref) {
248+
file_set_roots.push(VfsPath::from(manifest.to_owned()));
249+
entries.push(manifest.to_owned());
250+
}
245251

246-
res.watch.push(res.load.len());
247-
res.load.push(entry);
248-
local_filesets.push(fsc.len() as u64);
249-
fsc.add_file_set(file_set_roots)
252+
// In case of detached files we do **not** look for a rust-analyzer.toml.
253+
if !matches!(ws.kind, ProjectWorkspaceKind::DetachedFile { .. }) {
254+
let ws_root = ws.workspace_root();
255+
let ratoml_path = {
256+
let mut p = ws_root.to_path_buf();
257+
p.push("rust-analyzer.toml");
258+
p
259+
};
260+
file_set_roots.push(VfsPath::from(ratoml_path.to_owned()));
261+
entries.push(ratoml_path.to_owned());
262+
}
263+
264+
if !file_set_roots.is_empty() {
265+
let entry = vfs::loader::Entry::Files(entries);
266+
res.watch.push(res.load.len());
267+
res.load.push(entry);
268+
local_filesets.push(fsc.len() as u64);
269+
fsc.add_file_set(file_set_roots)
270+
}
250271
}
251272

252273
let fsc = fsc.build();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ impl ProjectJson {
291291
self.manifest.as_ref().map_or(&self.project_root, |manifest| manifest.as_ref())
292292
}
293293

294+
/// Returns the path to the project's root folder.
295+
pub fn project_root(&self) -> &AbsPath {
296+
&self.project_root
297+
}
298+
294299
pub fn runnables(&self) -> &[Runnable] {
295300
&self.runnables
296301
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ impl ProjectWorkspace {
523523
}
524524
}
525525

526+
pub fn workspace_root(&self) -> &AbsPath {
527+
match &self.kind {
528+
ProjectWorkspaceKind::Cargo { cargo, .. } => cargo.workspace_root(),
529+
ProjectWorkspaceKind::Json(project) => project.project_root(),
530+
ProjectWorkspaceKind::DetachedFile { file, .. } => file.parent(),
531+
}
532+
}
533+
526534
pub fn manifest(&self) -> Option<&ManifestPath> {
527535
match &self.kind {
528536
ProjectWorkspaceKind::Cargo { cargo, .. } => Some(cargo.manifest_path()),

0 commit comments

Comments
 (0)