aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/source_binder.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index ea20cd15a..4a9921a85 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -205,19 +205,8 @@ pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> R
205 // TODO const/static/array length 205 // TODO const/static/array length
206 None 206 None
207 } 207 }
208 } else if let Some(module) = ast::Module::cast(node) {
209 Some(module_from_declaration(db, file_id, module)?.resolver(db))
210 } else if let Some(_) = ast::SourceFile::cast(node) {
211 Some(module_from_source(db, file_id.into(), None)?.resolver(db))
212 } else if let Some(s) = ast::StructDef::cast(node) {
213 let module = module_from_child_node(db, file_id, s.syntax())?;
214 Some(struct_from_module(db, module, s).resolver(db))
215 } else if let Some(e) = ast::EnumDef::cast(node) {
216 let module = module_from_child_node(db, file_id, e.syntax())?;
217 Some(enum_from_module(db, module, e).resolver(db))
218 } else { 208 } else {
219 // TODO add missing cases 209 try_get_resolver_for_node(db, file_id, node)
220 None
221 } 210 }
222 }) 211 })
223 }) 212 })
@@ -236,20 +225,32 @@ pub fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNo
236 // TODO const/static/array length 225 // TODO const/static/array length
237 None 226 None
238 } 227 }
239 } else if let Some(module) = ast::Module::cast(node) {
240 Some(module_from_declaration(db, file_id, module)?.resolver(db))
241 } else if let Some(_) = ast::SourceFile::cast(node) {
242 Some(module_from_source(db, file_id.into(), None)?.resolver(db))
243 } else if let Some(s) = ast::StructDef::cast(node) {
244 let module = module_from_child_node(db, file_id, s.syntax())?;
245 Some(struct_from_module(db, module, s).resolver(db))
246 } else if let Some(e) = ast::EnumDef::cast(node) {
247 let module = module_from_child_node(db, file_id, e.syntax())?;
248 Some(enum_from_module(db, module, e).resolver(db))
249 } else { 228 } else {
250 // TODO add missing cases 229 try_get_resolver_for_node(db, file_id, node)
251 None
252 } 230 }
253 }) 231 })
254 .unwrap_or_default() 232 .unwrap_or_default()
255} 233}
234
235fn try_get_resolver_for_node(
236 db: &impl HirDatabase,
237 file_id: FileId,
238 node: &SyntaxNode,
239) -> Option<Resolver> {
240 if let Some(module) = ast::Module::cast(node) {
241 Some(module_from_declaration(db, file_id, module)?.resolver(db))
242 } else if let Some(_) = ast::SourceFile::cast(node) {
243 Some(module_from_source(db, file_id.into(), None)?.resolver(db))
244 } else if let Some(s) = ast::StructDef::cast(node) {
245 let module = module_from_child_node(db, file_id, s.syntax())?;
246 Some(struct_from_module(db, module, s).resolver(db))
247 } else if let Some(e) = ast::EnumDef::cast(node) {
248 let module = module_from_child_node(db, file_id, e.syntax())?;
249 Some(enum_from_module(db, module, e).resolver(db))
250 } else if let Some(f) = ast::FnDef::cast(node) {
251 function_from_source(db, file_id, f).map(|f| f.resolver(db))
252 } else {
253 // TODO add missing cases
254 None
255 }
256}