aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model_api.rs6
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs19
-rw-r--r--crates/ra_hir/src/impl_block.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs2
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs8
-rw-r--r--crates/ra_ide_api/src/runnables.rs3
6 files changed, 18 insertions, 22 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 5db53a34f..aed0ea958 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -78,12 +78,12 @@ pub enum Problem {
78 78
79impl Module { 79impl Module {
80 /// Name of this module. 80 /// Name of this module.
81 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 81 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
82 self.name_impl(db) 82 self.name_impl(db)
83 } 83 }
84 84
85 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 85 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
86 pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { 86 pub fn definition_source(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) {
87 self.definition_source_impl(db) 87 self.definition_source_impl(db)
88 } 88 }
89 89
@@ -92,7 +92,7 @@ impl Module {
92 pub fn declaration_source( 92 pub fn declaration_source(
93 &self, 93 &self,
94 db: &impl HirDatabase, 94 db: &impl HirDatabase,
95 ) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> { 95 ) -> Option<(FileId, TreeArc<ast::Module>)> {
96 self.declaration_source_impl(db) 96 self.declaration_source_impl(db)
97 } 97 }
98 98
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 67808d282..127dcc570 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -30,17 +30,14 @@ impl Module {
30 Module::new(def_id) 30 Module::new(def_id)
31 } 31 }
32 32
33 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 33 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option<Name> {
34 let loc = self.def_id.loc(db); 34 let loc = self.def_id.loc(db);
35 let module_tree = db.module_tree(loc.source_root_id); 35 let module_tree = db.module_tree(loc.source_root_id);
36 let link = ctry!(loc.module_id.parent_link(&module_tree)); 36 let link = loc.module_id.parent_link(&module_tree)?;
37 Ok(Some(link.name(&module_tree).clone())) 37 Some(link.name(&module_tree).clone())
38 } 38 }
39 39
40 pub fn definition_source_impl( 40 pub fn definition_source_impl(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) {
41 &self,
42 db: &impl HirDatabase,
43 ) -> Cancelable<(FileId, ModuleSource)> {
44 let loc = self.def_id.loc(db); 41 let loc = self.def_id.loc(db);
45 let file_id = loc.source_item_id.file_id.as_original_file(); 42 let file_id = loc.source_item_id.file_id.as_original_file();
46 let syntax_node = db.file_item(loc.source_item_id); 43 let syntax_node = db.file_item(loc.source_item_id);
@@ -50,23 +47,23 @@ impl Module {
50 let module = ast::Module::cast(&syntax_node).unwrap(); 47 let module = ast::Module::cast(&syntax_node).unwrap();
51 ModuleSource::Module(module.to_owned()) 48 ModuleSource::Module(module.to_owned())
52 }; 49 };
53 Ok((file_id, module_source)) 50 (file_id, module_source)
54 } 51 }
55 52
56 pub fn declaration_source_impl( 53 pub fn declaration_source_impl(
57 &self, 54 &self,
58 db: &impl HirDatabase, 55 db: &impl HirDatabase,
59 ) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> { 56 ) -> Option<(FileId, TreeArc<ast::Module>)> {
60 let loc = self.def_id.loc(db); 57 let loc = self.def_id.loc(db);
61 let module_tree = db.module_tree(loc.source_root_id); 58 let module_tree = db.module_tree(loc.source_root_id);
62 let link = ctry!(loc.module_id.parent_link(&module_tree)); 59 let link = loc.module_id.parent_link(&module_tree)?;
63 let file_id = link 60 let file_id = link
64 .owner(&module_tree) 61 .owner(&module_tree)
65 .source(&module_tree) 62 .source(&module_tree)
66 .file_id 63 .file_id
67 .as_original_file(); 64 .as_original_file();
68 let src = link.source(&module_tree, db); 65 let src = link.source(&module_tree, db);
69 Ok(Some((file_id, src))) 66 Some((file_id, src))
70 } 67 }
71 68
72 pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 69 pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index c9a9fb99f..ce9087b49 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -167,7 +167,7 @@ impl ModuleImplBlocks {
167 } 167 }
168 168
169 fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { 169 fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> {
170 let (file_id, module_source) = module.definition_source(db)?; 170 let (file_id, module_source) = module.definition_source(db);
171 let node = match &module_source { 171 let node = match &module_source {
172 ModuleSource::SourceFile(node) => node.syntax(), 172 ModuleSource::SourceFile(node) => node.syntax(),
173 ModuleSource::Module(node) => node 173 ModuleSource::Module(node) => node
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 770a0fdf2..f422bb9a7 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -20,7 +20,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
20 } 20 }
21 21
22 let module_scope = module.scope(ctx.db)?; 22 let module_scope = module.scope(ctx.db)?;
23 let (file_id, _) = module.definition_source(ctx.db)?; 23 let (file_id, _) = module.definition_source(ctx.db);
24 module_scope 24 module_scope
25 .entries() 25 .entries()
26 .filter(|(_name, res)| { 26 .filter(|(_name, res)| {
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 230d0f67a..7562b9a1f 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -73,9 +73,9 @@ impl NavigationTarget {
73 db: &RootDatabase, 73 db: &RootDatabase,
74 module: hir::Module, 74 module: hir::Module,
75 ) -> Cancelable<NavigationTarget> { 75 ) -> Cancelable<NavigationTarget> {
76 let (file_id, source) = module.definition_source(db)?; 76 let (file_id, source) = module.definition_source(db);
77 let name = module 77 let name = module
78 .name(db)? 78 .name(db)
79 .map(|it| it.to_string().into()) 79 .map(|it| it.to_string().into())
80 .unwrap_or_default(); 80 .unwrap_or_default();
81 let res = match source { 81 let res = match source {
@@ -94,10 +94,10 @@ impl NavigationTarget {
94 module: hir::Module, 94 module: hir::Module,
95 ) -> Cancelable<NavigationTarget> { 95 ) -> Cancelable<NavigationTarget> {
96 let name = module 96 let name = module
97 .name(db)? 97 .name(db)
98 .map(|it| it.to_string().into()) 98 .map(|it| it.to_string().into())
99 .unwrap_or_default(); 99 .unwrap_or_default();
100 if let Some((file_id, source)) = module.declaration_source(db)? { 100 if let Some((file_id, source)) = module.declaration_source(db) {
101 return Ok(NavigationTarget::from_syntax( 101 return Ok(NavigationTarget::from_syntax(
102 file_id, 102 file_id,
103 name, 103 name,
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 9fa0f79a6..c0d4bda94 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -83,8 +83,7 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
83 .ok()? 83 .ok()?
84 .into_iter() 84 .into_iter()
85 .rev() 85 .rev()
86 .filter_map(|it| it.name(db).ok()) 86 .filter_map(|it| it.name(db))
87 .filter_map(|it| it)
88 .join("::"); 87 .join("::");
89 Some(Runnable { 88 Some(Runnable {
90 range, 89 range,