diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs index 9550510ca6d..7a57ab3b9b7 100644 --- a/crates/ide_assists/src/handlers/extract_variable.rs +++ b/crates/ide_assists/src/handlers/extract_variable.rs @@ -160,6 +160,9 @@ fn from(to_extract: &ast::Expr) -> Option { .ancestors() .take_while(|it| !ast::Item::can_cast(it.kind()) || ast::MacroCall::can_cast(it.kind())) .find_map(|node| { + if ast::MacroCall::can_cast(node.kind()) { + return None; + } if let Some(expr) = node.parent().and_then(ast::StmtList::cast).and_then(|it| it.tail_expr()) { @@ -816,6 +819,32 @@ fn foo() { ) } + #[test] + fn extract_macro_call() { + check_assist( + extract_variable, + r" +struct Vec; +macro_rules! vec { + () => {Vec} +} +fn main() { + let _ = $0vec![]$0; +} +", + r" +struct Vec; +macro_rules! vec { + () => {Vec} +} +fn main() { + let $0vec = vec![]; + let _ = vec; +} +", + ); + } + #[test] fn test_extract_var_for_return_not_applicable() { check_assist_not_applicable(extract_variable, "fn foo() { $0return$0; } ");