diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/has_source.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 63b8fd369..76c32fc17 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use either::Either; | 3 | use either::Either; |
4 | use hir_def::{ | 4 | use hir_def::{ |
5 | nameres::ModuleSource, | 5 | nameres::{ModuleOrigin, ModuleSource}, |
6 | src::{HasChildSource, HasSource as _}, | 6 | src::{HasChildSource, HasSource as _}, |
7 | Lookup, VariantId, | 7 | Lookup, VariantId, |
8 | }; | 8 | }; |
@@ -29,6 +29,14 @@ impl Module { | |||
29 | def_map[self.id.local_id].definition_source(db.upcast()) | 29 | def_map[self.id.local_id].definition_source(db.upcast()) |
30 | } | 30 | } |
31 | 31 | ||
32 | pub fn is_mod_rs(self, db: &dyn HirDatabase) -> bool { | ||
33 | let def_map = db.crate_def_map(self.id.krate); | ||
34 | match def_map[self.id.local_id].origin { | ||
35 | ModuleOrigin::File { is_mod_rs, .. } => is_mod_rs, | ||
36 | _ => false, | ||
37 | } | ||
38 | } | ||
39 | |||
32 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. | 40 | /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. |
33 | /// `None` for the crate root. | 41 | /// `None` for the crate root. |
34 | pub fn declaration_source(self, db: &dyn HirDatabase) -> Option<InFile<ast::Module>> { | 42 | pub fn declaration_source(self, db: &dyn HirDatabase) -> Option<InFile<ast::Module>> { |