From d94dcfa8414d2701caba8e883c448ae7a5324a2e Mon Sep 17 00:00:00 2001 From: roife Date: Wed, 10 Jul 2024 01:23:27 +0800 Subject: [PATCH] fix: ensure that highlight_related works for macro_expr --- crates/ide/src/goto_definition.rs | 1 - crates/ide/src/highlight_related.rs | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 284fd7861d..ed9db32631 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -14,7 +14,6 @@ use ide_db::{ FileId, RootDatabase, }; use itertools::Itertools; -use span::FileRange; use syntax::{ ast::{self, HasLoopBody, Label}, match_ast, AstNode, AstToken, diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index 065c3f2452..b1efd90d4e 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -575,12 +575,20 @@ impl<'a> WalkExpandedExprCtx<'a> { } if let ast::Expr::MacroExpr(expr) = expr { - if let Some(expanded) = expr - .macro_call() - .and_then(|call| self.sema.expand(&call)) - .and_then(ast::MacroStmts::cast) + if let Some(expanded) = + expr.macro_call().and_then(|call| self.sema.expand(&call)) { - self.handle_expanded(expanded, cb); + match_ast! { + match expanded { + ast::MacroStmts(it) => { + self.handle_expanded(it, cb); + }, + ast::Expr(it) => { + self.walk(&it, cb); + }, + _ => {} + } + } } } }