aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_impl/krate.rs
blob: 914414fc3e0eaa5f7167f3887e6d3f708d7dd343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::{
    Crate, CrateDependency, AsName, Module, DefDatabase,
};

impl Crate {
    pub(crate) fn dependencies_impl(&self, db: &impl DefDatabase) -> Vec<CrateDependency> {
        let crate_graph = db.crate_graph();
        crate_graph
            .dependencies(self.crate_id)
            .map(|dep| {
                let krate = Crate { crate_id: dep.crate_id() };
                let name = dep.as_name();
                CrateDependency { krate, name }
            })
            .collect()
    }
    pub(crate) fn root_module_impl(&self, db: &impl DefDatabase) -> Option<Module> {
        let module_id = db.crate_def_map(*self).root();
        let module = Module { krate: *self, module_id };
        Some(module)
    }
}