about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-17 17:12:14 +0000
committerGitHub <noreply@github.com>2022-01-17 17:12:14 +0000
commit8be2be8c794192c32b1814d6a0be04c68af13855 (patch)
treecd852f42261fd61d6a7ea83cc04f35c2bbe027c4
parent1861654623f99e879ebace09e286dc96cb980776 (diff)
parenta3d06f824b4c2360a675b8a206cc43e200276609 (diff)
downloadrust-8be2be8c794192c32b1814d6a0be04c68af13855.tar.gz
rust-8be2be8c794192c32b1814d6a0be04c68af13855.zip
Merge #11308
11308: fix: status: output all crates a file belongs to r=jonas-schievink a=jonas-schievink

While investigating https://github.com/rust-analyzer/rust-analyzer/issues/11300 I noticed that we only output the first crate, which masks the reason for that issue – the file in question is the root of multiple crates, and one is missing dependencies.

This PR makes "Rust Analyzer: Status" include *every* crate a file is part of.

bors r+

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
-rw-r--r--crates/ide/src/status.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs
index 9f589c1ea1a..ea2b7906e9e 100644
--- a/crates/ide/src/status.rs
+++ b/crates/ide/src/status.rs
@@ -45,23 +45,23 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
 
     if let Some(file_id) = file_id {
         format_to!(buf, "\nFile info:\n");
-        let krate = crate::parent_module::crate_for(db, file_id).pop();
-        match krate {
-            Some(krate) => {
-                let crate_graph = db.crate_graph();
-                let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
-                    Some(it) => format!("{}({:?})", it, krate),
-                    None => format!("{:?}", krate),
-                };
-                format_to!(buf, "Crate: {}\n", display_crate(krate));
-                let deps = crate_graph[krate]
-                    .dependencies
-                    .iter()
-                    .map(|dep| format!("{}={:?}", dep.name, dep.crate_id))
-                    .format(", ");
-                format_to!(buf, "Dependencies: {}\n", deps);
-            }
-            None => format_to!(buf, "Does not belong to any crate"),
+        let crates = crate::parent_module::crate_for(db, file_id);
+        if crates.is_empty() {
+            format_to!(buf, "Does not belong to any crate");
+        }
+        let crate_graph = db.crate_graph();
+        for krate in crates {
+            let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
+                Some(it) => format!("{}({:?})", it, krate),
+                None => format!("{:?}", krate),
+            };
+            format_to!(buf, "Crate: {}\n", display_crate(krate));
+            let deps = crate_graph[krate]
+                .dependencies
+                .iter()
+                .map(|dep| format!("{}={:?}", dep.name, dep.crate_id))
+                .format(", ");
+            format_to!(buf, "Dependencies: {}\n", deps);
         }
     }