1
- use hir:: { HasSource , HirDisplay , Module , Semantics , TypeInfo } ;
1
+ use hir:: { Adt , HasSource , HirDisplay , Module , Semantics , TypeInfo } ;
2
2
use ide_db:: {
3
3
base_db:: FileId ,
4
4
defs:: { Definition , NameRefClass } ,
@@ -145,7 +145,8 @@ fn gen_method(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
145
145
return None ;
146
146
}
147
147
let ( impl_, file) = get_adt_source ( ctx, & adt, fn_name. text ( ) . as_str ( ) ) ?;
148
- let ( target, insert_offset) = get_method_target ( ctx, & target_module, & impl_) ?;
148
+ let ( target, insert_offset) = get_method_target ( ctx, & impl_, & adt) ?;
149
+
149
150
let function_builder =
150
151
FunctionBuilder :: from_method_call ( ctx, & call, & fn_name, target_module, target) ?;
151
152
let text_range = call. syntax ( ) . text_range ( ) ;
@@ -418,14 +419,13 @@ fn get_fn_target(
418
419
419
420
fn get_method_target (
420
421
ctx : & AssistContext < ' _ > ,
421
- target_module : & Module ,
422
422
impl_ : & Option < ast:: Impl > ,
423
+ adt : & Adt ,
423
424
) -> Option < ( GeneratedFunctionTarget , TextSize ) > {
424
425
let target = match impl_ {
425
426
Some ( impl_) => next_space_for_fn_in_impl ( impl_) ?,
426
427
None => {
427
- next_space_for_fn_in_module ( ctx. sema . db , & target_module. definition_source ( ctx. sema . db ) ) ?
428
- . 1
428
+ GeneratedFunctionTarget :: BehindItem ( adt. source ( ctx. sema . db ) ?. syntax ( ) . value . clone ( ) )
429
429
}
430
430
} ;
431
431
Some ( ( target. clone ( ) , get_insert_offset ( & target) ) )
@@ -444,7 +444,7 @@ fn assoc_fn_target_info(
444
444
return None ;
445
445
}
446
446
let ( impl_, file) = get_adt_source ( ctx, & adt, fn_name) ?;
447
- let ( target, insert_offset) = get_method_target ( ctx, & module , & impl_ ) ?;
447
+ let ( target, insert_offset) = get_method_target ( ctx, & impl_ , & adt ) ?;
448
448
let adt_name = if impl_. is_none ( ) { Some ( adt. name ( ctx. sema . db ) ) } else { None } ;
449
449
Some ( TargetInfo :: new ( target_module, adt_name, target, file, insert_offset) )
450
450
}
@@ -1475,12 +1475,12 @@ fn foo() {S.bar$0();}
1475
1475
" ,
1476
1476
r"
1477
1477
struct S;
1478
- fn foo() {S.bar();}
1479
1478
impl S {
1480
1479
fn bar(&self) ${0:-> _} {
1481
1480
todo!()
1482
1481
}
1483
1482
}
1483
+ fn foo() {S.bar();}
1484
1484
" ,
1485
1485
)
1486
1486
}
@@ -1547,16 +1547,16 @@ mod s {
1547
1547
" ,
1548
1548
r"
1549
1549
struct S;
1550
- mod s {
1551
- fn foo() {
1552
- super::S.bar();
1553
- }
1554
- }
1555
1550
impl S {
1556
1551
fn bar(&self) ${0:-> _} {
1557
1552
todo!()
1558
1553
}
1559
1554
}
1555
+ mod s {
1556
+ fn foo() {
1557
+ super::S.bar();
1558
+ }
1559
+ }
1560
1560
1561
1561
" ,
1562
1562
)
@@ -1572,12 +1572,12 @@ fn foo() {$0S.bar();}
1572
1572
" ,
1573
1573
r"
1574
1574
struct S;
1575
- fn foo() {S.bar();}
1576
1575
impl S {
1577
1576
fn bar(&self) ${0:-> _} {
1578
1577
todo!()
1579
1578
}
1580
1579
}
1580
+ fn foo() {S.bar();}
1581
1581
" ,
1582
1582
)
1583
1583
}
@@ -1592,12 +1592,12 @@ fn foo() {S::bar$0();}
1592
1592
" ,
1593
1593
r"
1594
1594
struct S;
1595
- fn foo() {S::bar();}
1596
1595
impl S {
1597
1596
fn bar() ${0:-> _} {
1598
1597
todo!()
1599
1598
}
1600
1599
}
1600
+ fn foo() {S::bar();}
1601
1601
" ,
1602
1602
)
1603
1603
}
@@ -1659,12 +1659,12 @@ fn foo() {$0S::bar();}
1659
1659
" ,
1660
1660
r"
1661
1661
struct S;
1662
- fn foo() {S::bar();}
1663
1662
impl S {
1664
1663
fn bar() ${0:-> _} {
1665
1664
todo!()
1666
1665
}
1667
1666
}
1667
+ fn foo() {S::bar();}
1668
1668
" ,
1669
1669
)
1670
1670
}
@@ -1834,14 +1834,14 @@ fn main() {
1834
1834
" ,
1835
1835
r"
1836
1836
enum Foo {}
1837
- fn main() {
1838
- Foo::new();
1839
- }
1840
1837
impl Foo {
1841
1838
fn new() ${0:-> _} {
1842
1839
todo!()
1843
1840
}
1844
1841
}
1842
+ fn main() {
1843
+ Foo::new();
1844
+ }
1845
1845
" ,
1846
1846
)
1847
1847
}
0 commit comments