aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model_api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r--crates/ra_hir/src/code_model_api.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index e8b3a1fb6..63e2e34e8 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -1,6 +1,6 @@
1use ra_db::{CrateId, Cancelable}; 1use ra_db::{CrateId, Cancelable};
2 2
3use crate::{Module, Name, db::HirDatabase}; 3use crate::{Name, db::HirDatabase, DefId};
4 4
5/// hir::Crate describes a single crate. It's the main inteface with which 5/// hir::Crate describes a single crate. It's the main inteface with which
6/// crate's dependencies interact. Mostly, it should be just a proxy for the 6/// crate's dependencies interact. Mostly, it should be just a proxy for the
@@ -24,3 +24,24 @@ impl Crate {
24 self.root_module_impl(db) 24 self.root_module_impl(db)
25 } 25 }
26} 26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Hash)]
29pub struct Module {
30 pub(crate) def_id: DefId,
31}
32
33impl Module {
34 /// Returns the crate this module is part of.
35 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
36 self.krate_impl(db)
37 }
38
39 pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> {
40 self.crate_root_impl(db)
41 }
42
43 /// Finds a child module with the specified name.
44 pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
45 self.child_impl(db, name)
46 }
47}