about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs4
-rw-r--r--crates/ide/src/expand_macro.rs20
2 files changed, 21 insertions, 3 deletions
diff --git a/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs b/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs
index 16e609b1a7e..b5db8c1967b 100644
--- a/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs
+++ b/crates/ide-db/src/syntax_helpers/insert_whitespace_into_node.rs
@@ -57,7 +57,7 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
             |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };
 
         match tok.kind() {
-            k if is_text(k) && is_next(|it| !it.is_punct(), true) => {
+            k if is_text(k) && is_next(|it| !it.is_punct() || it == UNDERSCORE, false) => {
                 mods.push(do_ws(after, tok));
             }
             L_CURLY if is_next(|it| it != R_CURLY, true) => {
@@ -118,5 +118,5 @@ pub fn insert_ws_into(syn: SyntaxNode) -> SyntaxNode {
 }
 
 fn is_text(k: SyntaxKind) -> bool {
-    k.is_keyword() || k.is_literal() || k == IDENT
+    k.is_keyword() || k.is_literal() || k == IDENT || k == UNDERSCORE
 }
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs
index e4061016e60..a578aba01f3 100644
--- a/crates/ide/src/expand_macro.rs
+++ b/crates/ide/src/expand_macro.rs
@@ -238,6 +238,24 @@ fn main() {
     }
 
     #[test]
+    fn macro_expand_underscore() {
+        check(
+            r#"
+macro_rules! bar {
+    ($i:tt) => { for _ in 0..$i {} }
+}
+fn main() {
+    ba$0r!(42);
+}
+"#,
+            expect![[r#"
+                bar
+                for _ in 0..42{}
+                "#]],
+        );
+    }
+
+    #[test]
     fn macro_expand_recursive_expansion() {
         check(
             r#"
@@ -385,7 +403,7 @@ fn main() {
 "#,
             expect![[r#"
                 foo
-                0 "#]],
+                0"#]],
         );
     }