diff options
author | Aleksey Kladov <[email protected]> | 2019-01-04 22:37:40 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-06 14:35:29 +0000 |
commit | 147b0f94e60f66c73ee1ca1726de97d76721bfda (patch) | |
tree | 7eca3e190d1de5b3c431585c8c554f03e7f26bb8 /crates/ra_hir/src/code_model_api.rs | |
parent | 9a820dc0ee23051137e4909d4698fe71930c04bc (diff) |
Start code_model::Module
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 23 |
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 @@ | |||
1 | use ra_db::{CrateId, Cancelable}; | 1 | use ra_db::{CrateId, Cancelable}; |
2 | 2 | ||
3 | use crate::{Module, Name, db::HirDatabase}; | 3 | use 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)] | ||
29 | pub struct Module { | ||
30 | pub(crate) def_id: DefId, | ||
31 | } | ||
32 | |||
33 | impl 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 | } | ||