Simplify code with @Veykril's suggestion.
This commit is contained in:
parent
16654ce154
commit
769273ca4c
@ -34,25 +34,16 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
|||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
let tok = ctx.token_at_offset().right_biased()?;
|
let unexpanded = ctx.find_node_at_offset::<ast::MacroCall>()?;
|
||||||
|
let expanded = ctx.sema.expand(&unexpanded)?.clone_for_update();
|
||||||
|
|
||||||
let mut anc = tok.parent_ancestors();
|
let text_range = unexpanded.syntax().text_range();
|
||||||
let (_name, expanded, unexpanded) = loop {
|
|
||||||
let node = anc.next()?;
|
|
||||||
if let Some(mac) = ast::MacroCall::cast(node.clone()) {
|
|
||||||
break (
|
|
||||||
mac.path()?.segment()?.name_ref()?.to_string(),
|
|
||||||
ctx.sema.expand(&mac)?.clone_for_update(),
|
|
||||||
node,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("inline_macro", AssistKind::RefactorRewrite),
|
AssistId("inline_macro", AssistKind::RefactorRewrite),
|
||||||
format!("Inline macro"),
|
format!("Inline macro"),
|
||||||
unexpanded.text_range(),
|
text_range,
|
||||||
|builder| builder.replace(unexpanded.text_range(), expanded.to_string()),
|
|builder| builder.replace(text_range, expanded.to_string()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user