From a3d06f824b4c2360a675b8a206cc43e200276609 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 17 Jan 2022 18:10:01 +0100 Subject: [PATCH] status: output all crates a file belongs to --- crates/ide/src/status.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/ide/src/status.rs b/crates/ide/src/status.rs index 9f589c1ea1..ea2b7906e9 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) -> 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); } }