• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use ide_db::{
2     base_db::{CrateOrigin, FileId, SourceDatabase},
3     FxIndexSet, RootDatabase,
4 };
5 
6 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7 pub struct CrateInfo {
8     pub name: Option<String>,
9     pub version: Option<String>,
10     pub root_file_id: FileId,
11 }
12 
13 // Feature: Show Dependency Tree
14 //
15 // Shows a view tree with all the dependencies of this project
16 //
17 // |===
18 // | Editor  | Panel Name
19 //
20 // | VS Code | **Rust Dependencies**
21 // |===
22 //
23 // image::https://user-images.githubusercontent.com/5748995/229394139-2625beab-f4c9-484b-84ed-ad5dee0b1e1a.png[]
fetch_crates(db: &RootDatabase) -> FxIndexSet<CrateInfo>24 pub(crate) fn fetch_crates(db: &RootDatabase) -> FxIndexSet<CrateInfo> {
25     let crate_graph = db.crate_graph();
26     crate_graph
27         .iter()
28         .map(|crate_id| &crate_graph[crate_id])
29         .filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. }))
30         .map(|data| crate_info(data))
31         .collect()
32 }
33 
crate_info(data: &ide_db::base_db::CrateData) -> CrateInfo34 fn crate_info(data: &ide_db::base_db::CrateData) -> CrateInfo {
35     let crate_name = crate_name(data);
36     let version = data.version.clone();
37     CrateInfo { name: crate_name, version, root_file_id: data.root_file_id }
38 }
39 
crate_name(data: &ide_db::base_db::CrateData) -> Option<String>40 fn crate_name(data: &ide_db::base_db::CrateData) -> Option<String> {
41     data.display_name.as_ref().map(|it| it.canonical_name().to_owned())
42 }
43