From 5889bb27d673e4762490c21ad734e7fd9705d591 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 9 Jan 2021 00:17:34 +0100 Subject: Simplify --- crates/ide/src/call_hierarchy.rs | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 4d8983cb2..b29d1fef9 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -5,7 +5,7 @@ use indexmap::IndexMap; use hir::Semantics; use ide_db::call_info::FnCallNode; use ide_db::RootDatabase; -use syntax::{ast, match_ast, AstNode, TextRange}; +use syntax::{ast, AstNode, TextRange}; use crate::{ display::TryToNav, goto_definition, references, FilePosition, NavigationTarget, RangeInfo, @@ -57,15 +57,9 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio // This target is the containing function if let Some(nav) = syntax.ancestors().find_map(|node| { - match_ast! { - match node { - ast::Fn(it) => { - let def = sema.to_def(&it)?; - def.try_to_nav(sema.db) - }, - _ => None, - } - } + let fn_ = ast::Fn::cast(node)?; + let def = sema.to_def(&fn_)?; + def.try_to_nav(sema.db) }) { let relative_range = reference.file_range.range; calls.add(&nav, relative_range); @@ -91,17 +85,12 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio .filter_map(|node| FnCallNode::with_node_exact(&node)) .filter_map(|call_node| { let name_ref = call_node.name_ref()?; - - if let Some(func_target) = match &call_node { + let func_target = match call_node { FnCallNode::CallExpr(expr) => { //FIXME: Type::as_callable is broken let callable = sema.type_of_expr(&expr.expr()?)?.as_callable(db)?; match callable.kind() { - hir::CallableKind::Function(it) => { - let fn_def: hir::Function = it.into(); - let nav = fn_def.try_to_nav(db)?; - Some(nav) - } + hir::CallableKind::Function(it) => it.try_to_nav(db), _ => None, } } @@ -109,11 +98,8 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio let function = sema.resolve_method_call(&expr)?; function.try_to_nav(db) } - } { - Some((func_target, name_ref.syntax().text_range())) - } else { - None - } + }?; + Some((func_target, name_ref.syntax().text_range())) }) .for_each(|(nav, range)| calls.add(&nav, range)); -- cgit v1.2.3