fix: fix extract_variable not working on macro_call
This commit is contained in:
parent
142b6dc650
commit
a2365ea18a
@ -160,6 +160,9 @@ fn from(to_extract: &ast::Expr) -> Option<Anchor> {
|
||||
.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; } ");
|
||||
|
Loading…
Reference in New Issue
Block a user