@@ -7,7 +7,7 @@ use ide_db::{
7
7
imports:: insert_use:: remove_path_if_in_use_stmt,
8
8
path_transform:: PathTransform ,
9
9
search:: { FileReference , SearchScope } ,
10
- syntax_helpers:: node_ext:: expr_as_name_ref,
10
+ syntax_helpers:: { insert_whitespace_into_node :: insert_ws_into , node_ext:: expr_as_name_ref} ,
11
11
RootDatabase ,
12
12
} ;
13
13
use itertools:: { izip, Itertools } ;
@@ -301,7 +301,18 @@ fn inline(
301
301
params : & [ ( ast:: Pat , Option < ast:: Type > , hir:: Param ) ] ,
302
302
CallInfo { node, arguments, generic_arg_list } : & CallInfo ,
303
303
) -> ast:: Expr {
304
- let body = fn_body. clone_for_update ( ) ;
304
+ let body = if sema. hir_file_for ( fn_body. syntax ( ) ) . is_macro ( ) {
305
+ cov_mark:: hit!( inline_call_defined_in_macro) ;
306
+ if let Some ( body) = ast:: BlockExpr :: cast ( insert_ws_into ( fn_body. syntax ( ) . clone ( ) ) ) {
307
+ body
308
+ } else {
309
+ // FIXME(zachs18): I believe this should be unreachable,
310
+ // since insert_ws_into shouldn't change the kind of the SyntaxNode.
311
+ fn_body. clone_for_update ( )
312
+ }
313
+ } else {
314
+ fn_body. clone_for_update ( )
315
+ } ;
305
316
let usages_for_locals = |local| {
306
317
Definition :: Local ( local)
307
318
. usages ( sema)
@@ -1144,6 +1155,41 @@ fn bar() -> u32 {
1144
1155
x
1145
1156
}) + foo()
1146
1157
}
1158
+ "# ,
1159
+ )
1160
+ }
1161
+
1162
+ #[ test]
1163
+ fn inline_call_defined_in_macro ( ) {
1164
+ cov_mark:: check!( inline_call_defined_in_macro) ;
1165
+ check_assist (
1166
+ inline_call,
1167
+ r#"
1168
+ macro_rules! define_foo {
1169
+ () => { fn foo() -> u32 {
1170
+ let x = 0;
1171
+ x
1172
+ } };
1173
+ }
1174
+ define_foo!();
1175
+ fn bar() -> u32 {
1176
+ foo$0()
1177
+ }
1178
+ "# ,
1179
+ r#"
1180
+ macro_rules! define_foo {
1181
+ () => { fn foo() -> u32 {
1182
+ let x = 0;
1183
+ x
1184
+ } };
1185
+ }
1186
+ define_foo!();
1187
+ fn bar() -> u32 {
1188
+ {
1189
+ let x = 0;
1190
+ x
1191
+ }
1192
+ }
1147
1193
"# ,
1148
1194
)
1149
1195
}
0 commit comments