aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl/krate.rs
blob: cdd30b402cf336bf48f891d7cc6c032b09ad862a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use ra_db::CrateId;

use crate::{
    Crate, CrateDependency, AsName, Module,
    db::HirDatabase,
};

impl Crate {
    pub(crate) fn new(crate_id: CrateId) -> Crate {
        Crate { crate_id }
    }
    pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
        let crate_graph = db.crate_graph();
        crate_graph
            .dependencies(self.crate_id)
            .map(|dep| {
                let krate = Crate::new(dep.crate_id());
                let name = dep.as_name();
                CrateDependency { krate, name }
            })
            .collect()
    }
    pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option<Module> {
        let module_tree = db.module_tree(self.crate_id);
        let module_id = module_tree.modules().next()?;

        let module = Module {
            krate: self.crate_id,
            module_id,
        };
        Some(module)
    }
}