about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAli Bektas <bektasali@protonmail.com>2024-07-22 02:42:39 +0200
committerAli Bektas <bektasali@protonmail.com>2024-07-22 02:42:39 +0200
commitd5cfeb5f88fd8d80f3c39badcea8cd2e95dad96d (patch)
tree944a83e7cbe530f2606518d5b38cdd2011c750e6 /src
parent402e176f06f21d3bac348dbe09a2af689672b0c6 (diff)
downloadrust-d5cfeb5f88fd8d80f3c39badcea8cd2e95dad96d.tar.gz
rust-d5cfeb5f88fd8d80f3c39badcea8cd2e95dad96d.zip
Read rust-analyzer.toml files on startup
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/load-cargo/src/lib.rs35
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/project_json.rs5
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/workspace.rs8
3 files changed, 40 insertions, 8 deletions
diff --git a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
index 0f1ca0369ed..3310614c21a 100644
--- a/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/load-cargo/src/lib.rs
@@ -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,32 @@ 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 mut register = false;
+
+            if let Some(manifest) = ws.manifest().map(ManifestPath::as_ref) {
+                file_set_roots.push(VfsPath::from(manifest.to_owned()));
+                entries.push(manifest.to_owned());
+                register = true;
+            }
 
-            let entry = vfs::loader::Entry::Files(vec![manifest.to_owned()]);
+            // 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();
+                file_set_roots.push(VfsPath::from(ws_root.to_owned()));
+                entries.push(ws_root.to_owned());
+                register = true;
+            }
 
-            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 register {
+                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();
diff --git a/src/tools/rust-analyzer/crates/project-model/src/project_json.rs b/src/tools/rust-analyzer/crates/project-model/src/project_json.rs
index 421ef25a45a..cf0a6ad4025 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/project_json.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/project_json.rs
@@ -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
     }
diff --git a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
index 8c77da8f38a..bfbdf038357 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
@@ -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()),