aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/tests/test/main.rs1
-rw-r--r--crates/ra_hir/src/code_model_api.rs12
2 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_analysis/tests/test/main.rs b/crates/ra_analysis/tests/test/main.rs
index 26da7c10c..85911de92 100644
--- a/crates/ra_analysis/tests/test/main.rs
+++ b/crates/ra_analysis/tests/test/main.rs
@@ -31,6 +31,7 @@ fn test_unresolved_module_diagnostic() {
31 ); 31 );
32} 32}
33 33
34// FIXME: move this test to hir
34#[test] 35#[test]
35fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() { 36fn test_unresolved_module_diagnostic_no_diag_for_inline_mode() {
36 let (analysis, file_id) = single_file("mod foo {}"); 37 let (analysis, file_id) = single_file("mod foo {}");
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 0c7f743d4..d00d3246f 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -34,22 +34,23 @@ pub struct Module {
34 pub(crate) def_id: DefId, 34 pub(crate) def_id: DefId,
35} 35}
36 36
37/// An owned syntax node for a module. Unlike `ModuleSource`,
38/// this holds onto the AST for the whole file.
39pub enum ModuleSource { 37pub enum ModuleSource {
40 SourceFile(ast::SourceFileNode), 38 SourceFile(ast::SourceFileNode),
41 Module(ast::ModuleNode), 39 Module(ast::ModuleNode),
42} 40}
43 41
44impl Module { 42impl Module {
43 /// Name of this module.
45 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 44 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> {
46 self.name_impl(db) 45 self.name_impl(db)
47 } 46 }
48 47
48 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
49 pub fn defenition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { 49 pub fn defenition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> {
50 self.defenition_source_impl(db) 50 self.defenition_source_impl(db)
51 } 51 }
52 52 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
53 /// `None` for the crate root.
53 pub fn declaration_source( 54 pub fn declaration_source(
54 &self, 55 &self,
55 db: &impl HirDatabase, 56 db: &impl HirDatabase,
@@ -61,11 +62,12 @@ impl Module {
61 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 62 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
62 self.krate_impl(db) 63 self.krate_impl(db)
63 } 64 }
64 65 /// Topmost parent of this module. Every module has a `crate_root`, but some
66 /// might miss `krate`. This can happen if a module's file is not included
67 /// into any module tree of any target from Cargo.toml.
65 pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> { 68 pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> {
66 self.crate_root_impl(db) 69 self.crate_root_impl(db)
67 } 70 }
68
69 /// Finds a child module with the specified name. 71 /// Finds a child module with the specified name.
70 pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> { 72 pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
71 self.child_impl(db, name) 73 self.child_impl(db, name)