status: output all crates a file belongs to

This commit is contained in:
Jonas Schievink 2022-01-17 18:10:01 +01:00
parent 1861654623
commit a3d06f824b

View file

@ -45,23 +45,23 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
if let Some(file_id) = file_id { if let Some(file_id) = file_id {
format_to!(buf, "\nFile info:\n"); format_to!(buf, "\nFile info:\n");
let krate = crate::parent_module::crate_for(db, file_id).pop(); let crates = crate::parent_module::crate_for(db, file_id);
match krate { if crates.is_empty() {
Some(krate) => { format_to!(buf, "Does not belong to any crate");
let crate_graph = db.crate_graph(); }
let display_crate = |krate: CrateId| match &crate_graph[krate].display_name { let crate_graph = db.crate_graph();
Some(it) => format!("{}({:?})", it, krate), for krate in crates {
None => format!("{:?}", krate), let display_crate = |krate: CrateId| match &crate_graph[krate].display_name {
}; Some(it) => format!("{}({:?})", it, krate),
format_to!(buf, "Crate: {}\n", display_crate(krate)); None => format!("{:?}", krate),
let deps = crate_graph[krate] };
.dependencies format_to!(buf, "Crate: {}\n", display_crate(krate));
.iter() let deps = crate_graph[krate]
.map(|dep| format!("{}={:?}", dep.name, dep.crate_id)) .dependencies
.format(", "); .iter()
format_to!(buf, "Dependencies: {}\n", deps); .map(|dep| format!("{}={:?}", dep.name, dep.crate_id))
} .format(", ");
None => format_to!(buf, "Does not belong to any crate"), format_to!(buf, "Dependencies: {}\n", deps);
} }
} }