Skip to content

Commit 626dc65

Browse files
committed
fix: Insert spaces when inlining macros
1 parent c468e39 commit 626dc65

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use ide_db::syntax_helpers::insert_whitespace_into_node::insert_ws_into;
12
use syntax::ast::{self, AstNode};
23

34
use crate::{AssistContext, AssistId, AssistKind, Assists};
@@ -35,7 +36,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
3536
// ```
3637
pub(crate) fn inline_macro(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
3738
let unexpanded = ctx.find_node_at_offset::<ast::MacroCall>()?;
38-
let expanded = ctx.sema.expand(&unexpanded)?.clone_for_update();
39+
let expanded = insert_ws_into(ctx.sema.expand(&unexpanded)?.clone_for_update());
3940

4041
let text_range = unexpanded.syntax().text_range();
4142

@@ -230,4 +231,27 @@ fn f() { let result = foo$0(); }
230231
"#,
231232
);
232233
}
234+
235+
#[test]
236+
fn inline_macro_with_whitespace() {
237+
check_assist(
238+
inline_macro,
239+
r#"
240+
macro_rules! whitespace {
241+
() => {
242+
if true {}
243+
};
244+
}
245+
fn f() { whitespace$0!(); }
246+
"#,
247+
r#"
248+
macro_rules! whitespace {
249+
() => {
250+
if true {}
251+
};
252+
}
253+
fn f() { if true{}; }
254+
"#,
255+
)
256+
}
233257
}

0 commit comments

Comments
 (0)