diff --git a/crates/ide/src/interpret_function.rs b/crates/ide/src/interpret_function.rs index d06ffd535758..21697490482e 100644 --- a/crates/ide/src/interpret_function.rs +++ b/crates/ide/src/interpret_function.rs @@ -1,10 +1,10 @@ use hir::Semantics; -use ide_db::base_db::SourceDatabaseExt; -use ide_db::RootDatabase; -use ide_db::{base_db::FilePosition, LineIndexDatabase}; +use ide_db::{ + base_db::{FilePosition, SourceDatabaseExt}, + LineIndexDatabase, RootDatabase, +}; use std::{fmt::Write, time::Instant}; -use syntax::TextRange; -use syntax::{algo::find_node_at_offset, ast, AstNode}; +use syntax::{algo::ancestors_at_offset, ast, AstNode, TextRange}; // Feature: Interpret Function // @@ -28,7 +28,9 @@ fn find_and_interpret(db: &RootDatabase, position: FilePosition) -> Option(source_file.syntax(), position.offset)?; + let item = ancestors_at_offset(source_file.syntax(), position.offset) + .filter(|it| !ast::MacroCall::can_cast(it.kind())) + .find_map(ast::Item::cast)?; let def = match item { ast::Item::Fn(it) => sema.to_def(&it)?, _ => return None, diff --git a/crates/ide/src/view_hir.rs b/crates/ide/src/view_hir.rs index 738b370a068e..9abe54cd3903 100644 --- a/crates/ide/src/view_hir.rs +++ b/crates/ide/src/view_hir.rs @@ -20,7 +20,7 @@ fn body_hir(db: &RootDatabase, position: FilePosition) -> Option { let source_file = sema.parse(position.file_id); let item = ancestors_at_offset(source_file.syntax(), position.offset) - .filter(|it| ast::MacroCall::can_cast(it.kind())) + .filter(|it| !ast::MacroCall::can_cast(it.kind())) .find_map(ast::Item::cast)?; let def: DefWithBody = match item { ast::Item::Fn(it) => sema.to_def(&it)?.into(), diff --git a/crates/ide/src/view_mir.rs b/crates/ide/src/view_mir.rs index 52ed420669a7..08d810c13462 100644 --- a/crates/ide/src/view_mir.rs +++ b/crates/ide/src/view_mir.rs @@ -19,7 +19,7 @@ fn body_mir(db: &RootDatabase, position: FilePosition) -> Option { let source_file = sema.parse(position.file_id); let item = ancestors_at_offset(source_file.syntax(), position.offset) - .filter(|it| ast::MacroCall::can_cast(it.kind())) + .filter(|it| !ast::MacroCall::can_cast(it.kind())) .find_map(ast::Item::cast)?; let def: DefWithBody = match item { ast::Item::Fn(it) => sema.to_def(&it)?.into(),