@@ -13,7 +13,7 @@ use ide_db::{
13
13
use itertools:: { izip, Itertools } ;
14
14
use syntax:: {
15
15
ast:: { self , edit_in_place:: Indent , HasArgList , PathExpr } ,
16
- ted, AstNode ,
16
+ ted, AstNode , NodeOrToken , SyntaxKind ,
17
17
} ;
18
18
19
19
use crate :: {
@@ -311,6 +311,13 @@ fn inline(
311
311
} else {
312
312
fn_body. clone_for_update ( )
313
313
} ;
314
+ if let Some ( t) = body. syntax ( ) . ancestors ( ) . find_map ( ast:: Impl :: cast) . and_then ( |i| i. self_ty ( ) ) {
315
+ body. syntax ( )
316
+ . descendants_with_tokens ( )
317
+ . filter_map ( NodeOrToken :: into_token)
318
+ . filter ( |tok| tok. kind ( ) == SyntaxKind :: SELF_TYPE_KW )
319
+ . for_each ( |tok| ted:: replace ( tok, t. syntax ( ) ) ) ;
320
+ }
314
321
let usages_for_locals = |local| {
315
322
Definition :: Local ( local)
316
323
. usages ( sema)
@@ -345,6 +352,7 @@ fn inline(
345
352
}
346
353
} )
347
354
. collect ( ) ;
355
+
348
356
if function. self_param ( sema. db ) . is_some ( ) {
349
357
let this = || make:: name_ref ( "this" ) . syntax ( ) . clone_for_update ( ) ;
350
358
if let Some ( self_local) = params[ 0 ] . 2 . as_local ( sema. db ) {
@@ -1188,6 +1196,31 @@ fn bar() -> u32 {
1188
1196
x
1189
1197
}
1190
1198
}
1199
+ "# ,
1200
+ )
1201
+ }
1202
+
1203
+ #[ test]
1204
+ fn inline_call_with_self_type ( ) {
1205
+ check_assist (
1206
+ inline_call,
1207
+ r#"
1208
+ struct A(u32);
1209
+ impl A {
1210
+ fn f() -> Self { Self(114514) }
1211
+ }
1212
+ fn main() {
1213
+ A::f$0();
1214
+ }
1215
+ "# ,
1216
+ r#"
1217
+ struct A(u32);
1218
+ impl A {
1219
+ fn f() -> Self { Self(114514) }
1220
+ }
1221
+ fn main() {
1222
+ A(114514);
1223
+ }
1191
1224
"# ,
1192
1225
)
1193
1226
}
0 commit comments