mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Auto merge of #17661 - alibektas:read_ratoml_on_startup, r=Veykril
minor: Read workspace root ratomls on startup
This commit is contained in:
commit
fbfda1b566
3 changed files with 42 additions and 8 deletions
|
@ -15,7 +15,9 @@ use ide_db::{
|
|||
};
|
||||
use itertools::Itertools;
|
||||
use proc_macro_api::{MacroDylib, ProcMacroServer};
|
||||
use project_model::{CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace};
|
||||
use project_model::{
|
||||
CargoConfig, ManifestPath, PackageRoot, ProjectManifest, ProjectWorkspace, ProjectWorkspaceKind,
|
||||
};
|
||||
use span::Span;
|
||||
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf, VfsPath};
|
||||
|
||||
|
@ -238,15 +240,34 @@ impl ProjectFolders {
|
|||
|
||||
// register the workspace manifest as well, note that this currently causes duplicates for
|
||||
// non-virtual cargo workspaces! We ought to fix that
|
||||
for manifest in workspaces.iter().filter_map(|ws| ws.manifest().map(ManifestPath::as_ref)) {
|
||||
let file_set_roots: Vec<VfsPath> = vec![VfsPath::from(manifest.to_owned())];
|
||||
for ws in workspaces.iter() {
|
||||
let mut file_set_roots: Vec<VfsPath> = vec![];
|
||||
let mut entries = vec![];
|
||||
|
||||
let entry = vfs::loader::Entry::Files(vec![manifest.to_owned()]);
|
||||
if let Some(manifest) = ws.manifest().map(ManifestPath::as_ref) {
|
||||
file_set_roots.push(VfsPath::from(manifest.to_owned()));
|
||||
entries.push(manifest.to_owned());
|
||||
}
|
||||
|
||||
res.watch.push(res.load.len());
|
||||
res.load.push(entry);
|
||||
local_filesets.push(fsc.len() as u64);
|
||||
fsc.add_file_set(file_set_roots)
|
||||
// In case of detached files we do **not** look for a rust-analyzer.toml.
|
||||
if !matches!(ws.kind, ProjectWorkspaceKind::DetachedFile { .. }) {
|
||||
let ws_root = ws.workspace_root();
|
||||
let ratoml_path = {
|
||||
let mut p = ws_root.to_path_buf();
|
||||
p.push("rust-analyzer.toml");
|
||||
p
|
||||
};
|
||||
file_set_roots.push(VfsPath::from(ratoml_path.to_owned()));
|
||||
entries.push(ratoml_path.to_owned());
|
||||
}
|
||||
|
||||
if !file_set_roots.is_empty() {
|
||||
let entry = vfs::loader::Entry::Files(entries);
|
||||
res.watch.push(res.load.len());
|
||||
res.load.push(entry);
|
||||
local_filesets.push(fsc.len() as u64);
|
||||
fsc.add_file_set(file_set_roots)
|
||||
}
|
||||
}
|
||||
|
||||
let fsc = fsc.build();
|
||||
|
|
|
@ -291,6 +291,11 @@ impl ProjectJson {
|
|||
self.manifest.as_ref().map_or(&self.project_root, |manifest| manifest.as_ref())
|
||||
}
|
||||
|
||||
/// Returns the path to the project's root folder.
|
||||
pub fn project_root(&self) -> &AbsPath {
|
||||
&self.project_root
|
||||
}
|
||||
|
||||
pub fn runnables(&self) -> &[Runnable] {
|
||||
&self.runnables
|
||||
}
|
||||
|
|
|
@ -523,6 +523,14 @@ impl ProjectWorkspace {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn workspace_root(&self) -> &AbsPath {
|
||||
match &self.kind {
|
||||
ProjectWorkspaceKind::Cargo { cargo, .. } => cargo.workspace_root(),
|
||||
ProjectWorkspaceKind::Json(project) => project.project_root(),
|
||||
ProjectWorkspaceKind::DetachedFile { file, .. } => file.parent(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn manifest(&self) -> Option<&ManifestPath> {
|
||||
match &self.kind {
|
||||
ProjectWorkspaceKind::Cargo { cargo, .. } => Some(cargo.manifest_path()),
|
||||
|
|
Loading…
Reference in a new issue