From aedff7cdcfb2340a3a23b540b50cadc94a367428 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Jan 2020 11:00:17 +0100 Subject: Move utility functions down --- crates/ra_hir/src/source_analyzer.rs | 116 +++++++++++++++++------------------ 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'crates/ra_hir/src/source_analyzer.rs') diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index a2a9d968c..f0511c742 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs @@ -40,64 +40,6 @@ use crate::{ TypeParam, }; -fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option { - match_ast! { - match (node.value) { - ast::Module(it) => { - let src = node.with_value(it); - Some(crate::Module::from_declaration(db, src)?.id.resolver(db)) - }, - ast::SourceFile(it) => { - let src = node.with_value(ModuleSource::SourceFile(it)); - Some(crate::Module::from_definition(db, src)?.id.resolver(db)) - }, - ast::StructDef(it) => { - let src = node.with_value(it); - Some(Struct::from_source(db, src)?.id.resolver(db)) - }, - ast::EnumDef(it) => { - let src = node.with_value(it); - Some(Enum::from_source(db, src)?.id.resolver(db)) - }, - ast::ImplBlock(it) => { - let src = node.with_value(it); - Some(ImplBlock::from_source(db, src)?.id.resolver(db)) - }, - ast::TraitDef(it) => { - let src = node.with_value(it); - Some(Trait::from_source(db, src)?.id.resolver(db)) - }, - _ => match node.value.kind() { - FN_DEF | CONST_DEF | STATIC_DEF => { - let def = def_with_body_from_child_node(db, node)?; - let def = DefWithBodyId::from(def); - Some(def.resolver(db)) - } - // FIXME add missing cases - _ => None - } - } - } -} - -fn def_with_body_from_child_node( - db: &impl HirDatabase, - child: InFile<&SyntaxNode>, -) -> Option { - let _p = profile("def_with_body_from_child_node"); - child.cloned().ancestors_with_macros(db).find_map(|node| { - let n = &node.value; - match_ast! { - match n { - ast::FnDef(def) => { return Function::from_source(db, node.with_value(def)).map(DefWithBody::from); }, - ast::ConstDef(def) => { return Const::from_source(db, node.with_value(def)).map(DefWithBody::from); }, - ast::StaticDef(def) => { return Static::from_source(db, node.with_value(def)).map(DefWithBody::from); }, - _ => { None }, - } - } - }) -} - /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of /// original source files. It should not be used inside the HIR itself. #[derive(Debug)] @@ -487,6 +429,64 @@ impl SourceAnalyzer { } } +fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option { + match_ast! { + match (node.value) { + ast::Module(it) => { + let src = node.with_value(it); + Some(crate::Module::from_declaration(db, src)?.id.resolver(db)) + }, + ast::SourceFile(it) => { + let src = node.with_value(ModuleSource::SourceFile(it)); + Some(crate::Module::from_definition(db, src)?.id.resolver(db)) + }, + ast::StructDef(it) => { + let src = node.with_value(it); + Some(Struct::from_source(db, src)?.id.resolver(db)) + }, + ast::EnumDef(it) => { + let src = node.with_value(it); + Some(Enum::from_source(db, src)?.id.resolver(db)) + }, + ast::ImplBlock(it) => { + let src = node.with_value(it); + Some(ImplBlock::from_source(db, src)?.id.resolver(db)) + }, + ast::TraitDef(it) => { + let src = node.with_value(it); + Some(Trait::from_source(db, src)?.id.resolver(db)) + }, + _ => match node.value.kind() { + FN_DEF | CONST_DEF | STATIC_DEF => { + let def = def_with_body_from_child_node(db, node)?; + let def = DefWithBodyId::from(def); + Some(def.resolver(db)) + } + // FIXME add missing cases + _ => None + } + } + } +} + +fn def_with_body_from_child_node( + db: &impl HirDatabase, + child: InFile<&SyntaxNode>, +) -> Option { + let _p = profile("def_with_body_from_child_node"); + child.cloned().ancestors_with_macros(db).find_map(|node| { + let n = &node.value; + match_ast! { + match n { + ast::FnDef(def) => { return Function::from_source(db, node.with_value(def)).map(DefWithBody::from); }, + ast::ConstDef(def) => { return Const::from_source(db, node.with_value(def)).map(DefWithBody::from); }, + ast::StaticDef(def) => { return Static::from_source(db, node.with_value(def)).map(DefWithBody::from); }, + _ => { None }, + } + } + }) +} + fn scope_for( scopes: &ExprScopes, source_map: &BodySourceMap, -- cgit v1.2.3