@@ -13,7 +13,7 @@ use ide_db::{
1313use itertools:: { izip, Itertools } ;
1414use syntax:: {
1515 ast:: { self , edit_in_place:: Indent , HasArgList , PathExpr } ,
16- ted, AstNode ,
16+ ted, AstNode , NodeOrToken , SyntaxKind ,
1717} ;
1818
1919use crate :: {
@@ -311,6 +311,13 @@ fn inline(
311311 } else {
312312 fn_body. clone_for_update ( )
313313 } ;
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+ }
314321 let usages_for_locals = |local| {
315322 Definition :: Local ( local)
316323 . usages ( sema)
@@ -345,6 +352,7 @@ fn inline(
345352 }
346353 } )
347354 . collect ( ) ;
355+
348356 if function. self_param ( sema. db ) . is_some ( ) {
349357 let this = || make:: name_ref ( "this" ) . syntax ( ) . clone_for_update ( ) ;
350358 if let Some ( self_local) = params[ 0 ] . 2 . as_local ( sema. db ) {
@@ -1188,6 +1196,31 @@ fn bar() -> u32 {
11881196 x
11891197 }
11901198}
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+ }
11911224"# ,
11921225 )
11931226 }
0 commit comments