From 841feef79ee9349a9f82e4b642f22aa0f7abcae5 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 2 Jun 2021 21:39:53 +0200 Subject: Allow expand-macro to be invoked anywhere inside a macro call --- crates/ide/src/expand_macro.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index eebae5ebe..e0d01fa96 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -28,8 +28,8 @@ pub struct ExpandedMacro { pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option { let sema = Semantics::new(db); let file = sema.parse(position.file_id); - let name_ref = find_node_at_offset::(file.syntax(), position.offset)?; - let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?; + let mac = find_node_at_offset::(file.syntax(), position.offset)?; + let name = mac.path()?.segment()?.name_ref()?; let expanded = expand_macro_recur(&sema, &mac)?; @@ -37,7 +37,7 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option< // macro expansion may lose all white space information // But we hope someday we can use ra_fmt for that let expansion = insert_whitespaces(expanded); - Some(ExpandedMacro { name: name_ref.text().to_string(), expansion }) + Some(ExpandedMacro { name: name.to_string(), expansion }) } fn expand_macro_recur( -- cgit v1.2.3