Skip to content

Commit 769273c

Browse files
committed
Simplify code with @Veykril's suggestion.
1 parent 16654ce commit 769273c

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

crates/ide-assists/src/handlers/inline_macro.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,16 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
3434
// }
3535
// ```
3636
pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
37-
let tok = ctx.token_at_offset().right_biased()?;
38-
39-
let mut anc = tok.parent_ancestors();
40-
let (_name, expanded, unexpanded) = loop {
41-
let node = anc.next()?;
42-
if let Some(mac) = ast::MacroCall::cast(node.clone()) {
43-
break (
44-
mac.path()?.segment()?.name_ref()?.to_string(),
45-
ctx.sema.expand(&mac)?.clone_for_update(),
46-
node,
47-
);
48-
}
49-
};
37+
let unexpanded = ctx.find_node_at_offset::<ast::MacroCall>()?;
38+
let expanded = ctx.sema.expand(&unexpanded)?.clone_for_update();
39+
40+
let text_range = unexpanded.syntax().text_range();
5041

5142
acc.add(
5243
AssistId("inline_macro", AssistKind::RefactorRewrite),
5344
format!("Inline macro"),
54-
unexpanded.text_range(),
55-
|builder| builder.replace(unexpanded.text_range(), expanded.to_string()),
45+
text_range,
46+
|builder| builder.replace(text_range, expanded.to_string()),
5647
)
5748
}
5849

0 commit comments

Comments
 (0)