mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
fix: fix extract_variable not working on macro_call
This commit is contained in:
parent
142b6dc650
commit
a2365ea18a
1 changed files with 29 additions and 0 deletions
|
@ -160,6 +160,9 @@ impl 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 a new issue