more crate boilerplate

This commit is contained in:
Aleksey Kladov 2018-12-09 00:51:06 +03:00
parent 9c6c7ec2da
commit ca7e5905c1
5 changed files with 54 additions and 13 deletions

View file

@ -12,7 +12,7 @@ use ra_db::{SourceRootId, FileId, Cancelable};
use relative_path::RelativePathBuf;
use crate::{
DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId,
DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate,
arena::{Arena, Id},
};
@ -64,6 +64,15 @@ impl Module {
})
}
/// Returns the crate this module is part of.
pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
let root_id = self.module_id.crate_root(&self.tree);
let file_id = root_id.source(&self.tree).file_id();
let crate_graph = db.crate_graph();
let crate_id = crate_graph.crate_id_for_crate_root(file_id)?;
Some(Crate::new(crate_id))
}
/// The root of the tree this module is part of
pub fn crate_root(&self) -> Module {
let root_id = self.module_id.crate_root(&self.tree);