mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
more crate boilerplate
This commit is contained in:
parent
9c6c7ec2da
commit
ca7e5905c1
5 changed files with 54 additions and 13 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue