Skip to content

Commit

Permalink
fix: Fix view mir, hir and eval function not working when cursor is i…
Browse files Browse the repository at this point in the history
…nside macros
  • Loading branch information
Veykril committed Dec 10, 2023
1 parent 19387d3 commit 306c907
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions crates/ide/src/interpret_function.rs
Original file line number Diff line number Diff line change
@@ -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
//
Expand All @@ -28,7 +28,9 @@ fn find_and_interpret(db: &RootDatabase, position: FilePosition) -> Option<Strin
let sema = Semantics::new(db);
let source_file = sema.parse(position.file_id);

let item = find_node_at_offset::<ast::Item>(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,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/view_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/view_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn body_mir(db: &RootDatabase, position: FilePosition) -> Option<String> {
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(),
Expand Down

0 comments on commit 306c907

Please sign in to comment.