Skip to content

Commit e5c86ee

Browse files
bors[bot]Veykril
andauthored
Merge #9117
9117: Allow expand-macro to be invoked anywhere inside a macro call r=Veykril a=Veykril I don't really see a reason to only limit this to the name-ref of a macro. bors r+ Closes #4606 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 5193728 + 841feef commit e5c86ee

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

crates/ide/src/expand_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ pub struct ExpandedMacro {
2828
pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<ExpandedMacro> {
2929
let sema = Semantics::new(db);
3030
let file = sema.parse(position.file_id);
31-
let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), position.offset)?;
32-
let mac = name_ref.syntax().ancestors().find_map(ast::MacroCall::cast)?;
31+
let mac = find_node_at_offset::<ast::MacroCall>(file.syntax(), position.offset)?;
32+
let name = mac.path()?.segment()?.name_ref()?;
3333

3434
let expanded = expand_macro_recur(&sema, &mac)?;
3535

3636
// FIXME:
3737
// macro expansion may lose all white space information
3838
// But we hope someday we can use ra_fmt for that
3939
let expansion = insert_whitespaces(expanded);
40-
Some(ExpandedMacro { name: name_ref.text().to_string(), expansion })
40+
Some(ExpandedMacro { name: name.to_string(), expansion })
4141
}
4242

4343
fn expand_macro_recur(

0 commit comments

Comments
 (0)