Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-assists/src/handlers/inline_macro.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/ide-assists/src/handlers/inline_macro.rs b/crates/ide-assists/src/handlers/inline_macro.rs
index 1cf5402db8..81f1a8a73f 100644
--- a/crates/ide-assists/src/handlers/inline_macro.rs
+++ b/crates/ide-assists/src/handlers/inline_macro.rs
@@ -46,12 +46,14 @@ pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
"Inline macro".to_owned(),
text_range,
|builder| {
+ let editor = builder.make_editor(unexpanded.syntax());
let expanded = ctx.sema.parse_or_expand(macro_call.into());
let span_map = ctx.sema.db.expansion_span_map(macro_call);
// Don't call `prettify_macro_expansion()` outside the actual assist action; it does some heavy rowan tree manipulation,
// which can be very costly for big macros when it is done *even without the assist being invoked*.
let expanded = prettify_macro_expansion(ctx.db(), expanded, &span_map, target_crate_id);
- builder.replace(text_range, expanded.to_string())
+ editor.replace(unexpanded.syntax(), expanded);
+ builder.add_file_edits(ctx.vfs_file_id(), editor);
},
)
}
@@ -207,15 +209,15 @@ macro_rules! num {
inline_macro,
r#"
macro_rules! foo {
- () => {foo!()}
+ ($t:tt) => {foo!(1)}
}
-fn f() { let result = foo$0!(); }
+fn f() { let result = foo$0!(0); }
"#,
r#"
macro_rules! foo {
- () => {foo!()}
+ ($t:tt) => {foo!(1)}
}
-fn f() { let result = foo!(); }
+fn f() { let result = foo!(1); }
"#,
);
}