Skip to content

Commit ed39b45

Browse files
bors[bot]Veykril
andauthored
Merge #10635
10635: fix: fix extract_variable not working on macro_call r=Veykril a=Veykril Fixes #7410 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents e4ca952 + a2365ea commit ed39b45

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

crates/ide_assists/src/handlers/extract_variable.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ impl Anchor {
160160
.ancestors()
161161
.take_while(|it| !ast::Item::can_cast(it.kind()) || ast::MacroCall::can_cast(it.kind()))
162162
.find_map(|node| {
163+
if ast::MacroCall::can_cast(node.kind()) {
164+
return None;
165+
}
163166
if let Some(expr) =
164167
node.parent().and_then(ast::StmtList::cast).and_then(|it| it.tail_expr())
165168
{
@@ -816,6 +819,32 @@ fn foo() {
816819
)
817820
}
818821

822+
#[test]
823+
fn extract_macro_call() {
824+
check_assist(
825+
extract_variable,
826+
r"
827+
struct Vec;
828+
macro_rules! vec {
829+
() => {Vec}
830+
}
831+
fn main() {
832+
let _ = $0vec![]$0;
833+
}
834+
",
835+
r"
836+
struct Vec;
837+
macro_rules! vec {
838+
() => {Vec}
839+
}
840+
fn main() {
841+
let $0vec = vec![];
842+
let _ = vec;
843+
}
844+
",
845+
);
846+
}
847+
819848
#[test]
820849
fn test_extract_var_for_return_not_applicable() {
821850
check_assist_not_applicable(extract_variable, "fn foo() { $0return$0; } ");

0 commit comments

Comments
 (0)