aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/module.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-08 21:51:06 +0000
committerAleksey Kladov <[email protected]>2018-12-09 10:33:16 +0000
commitca7e5905c1daffbed6a08fe674ae821f99bd274d (patch)
tree754bc504f4a2d459e5e90dfbe312d23554fbb1bb /crates/ra_hir/src/module.rs
parent9c6c7ec2daacdbcaae8fe697b30d4c99aae69090 (diff)
more crate boilerplate
Diffstat (limited to 'crates/ra_hir/src/module.rs')
-rw-r--r--crates/ra_hir/src/module.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs
index e7a49f83a..c6bb76d56 100644
--- a/crates/ra_hir/src/module.rs
+++ b/crates/ra_hir/src/module.rs
@@ -12,7 +12,7 @@ use ra_db::{SourceRootId, FileId, Cancelable};
12use relative_path::RelativePathBuf; 12use relative_path::RelativePathBuf;
13 13
14use crate::{ 14use crate::{
15 DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, 15 DefKind, DefLoc, DefId, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate,
16 arena::{Arena, Id}, 16 arena::{Arena, Id},
17}; 17};
18 18
@@ -64,6 +64,15 @@ impl Module {
64 }) 64 })
65 } 65 }
66 66
67 /// Returns the crate this module is part of.
68 pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
69 let root_id = self.module_id.crate_root(&self.tree);
70 let file_id = root_id.source(&self.tree).file_id();
71 let crate_graph = db.crate_graph();
72 let crate_id = crate_graph.crate_id_for_crate_root(file_id)?;
73 Some(Crate::new(crate_id))
74 }
75
67 /// The root of the tree this module is part of 76 /// The root of the tree this module is part of
68 pub fn crate_root(&self) -> Module { 77 pub fn crate_root(&self) -> Module {
69 let root_id = self.module_id.crate_root(&self.tree); 78 let root_id = self.module_id.crate_root(&self.tree);