Skip to content

Commit 4e814e3

Browse files
committed
Auto merge of rust-lang#16078 - Veykril:fix-view-ir, r=Veykril
fix: Fix view mir, hir and eval function not working when cursor is inside macros I broke the view ones completely by inverting the macro check by accident a few days ago but we don't talk about that.
2 parents 9d87a23 + 306c907 commit 4e814e3

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

crates/ide/src/interpret_function.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use hir::Semantics;
2-
use ide_db::base_db::SourceDatabaseExt;
3-
use ide_db::RootDatabase;
4-
use ide_db::{base_db::FilePosition, LineIndexDatabase};
2+
use ide_db::{
3+
base_db::{FilePosition, SourceDatabaseExt},
4+
LineIndexDatabase, RootDatabase,
5+
};
56
use std::{fmt::Write, time::Instant};
6-
use syntax::TextRange;
7-
use syntax::{algo::find_node_at_offset, ast, AstNode};
7+
use syntax::{algo::ancestors_at_offset, ast, AstNode, TextRange};
88

99
// Feature: Interpret Function
1010
//
@@ -28,7 +28,9 @@ fn find_and_interpret(db: &RootDatabase, position: FilePosition) -> Option<Strin
2828
let sema = Semantics::new(db);
2929
let source_file = sema.parse(position.file_id);
3030

31-
let item = find_node_at_offset::<ast::Item>(source_file.syntax(), position.offset)?;
31+
let item = ancestors_at_offset(source_file.syntax(), position.offset)
32+
.filter(|it| !ast::MacroCall::can_cast(it.kind()))
33+
.find_map(ast::Item::cast)?;
3234
let def = match item {
3335
ast::Item::Fn(it) => sema.to_def(&it)?,
3436
_ => return None,

crates/ide/src/view_hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
2020
let source_file = sema.parse(position.file_id);
2121

2222
let item = ancestors_at_offset(source_file.syntax(), position.offset)
23-
.filter(|it| ast::MacroCall::can_cast(it.kind()))
23+
.filter(|it| !ast::MacroCall::can_cast(it.kind()))
2424
.find_map(ast::Item::cast)?;
2525
let def: DefWithBody = match item {
2626
ast::Item::Fn(it) => sema.to_def(&it)?.into(),

crates/ide/src/view_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn body_mir(db: &RootDatabase, position: FilePosition) -> Option<String> {
1919
let source_file = sema.parse(position.file_id);
2020

2121
let item = ancestors_at_offset(source_file.syntax(), position.offset)
22-
.filter(|it| ast::MacroCall::can_cast(it.kind()))
22+
.filter(|it| !ast::MacroCall::can_cast(it.kind()))
2323
.find_map(ast::Item::cast)?;
2424
let def: DefWithBody = match item {
2525
ast::Item::Fn(it) => sema.to_def(&it)?.into(),

0 commit comments

Comments
 (0)