@@ -174,10 +174,11 @@ fn add_func_to_accumulator(
174
174
label : String ,
175
175
) -> Option < ( ) > {
176
176
acc. add ( AssistId ( "generate_function" , AssistKind :: Generate ) , label, text_range, |builder| {
177
- let function_template = function_builder. render ( ) ;
177
+ let indent = IndentLevel :: from_node ( function_builder. target . syntax ( ) ) ;
178
+ let function_template = function_builder. render ( adt_name. is_some ( ) ) ;
178
179
let mut func = function_template. to_string ( ctx. config . snippet_cap ) ;
179
180
if let Some ( name) = adt_name {
180
- func = format ! ( "\n impl {} {{\n {}\n }} " , name, func) ;
181
+ func = format ! ( "\n {}impl {} {{\n {}\n {}}} " , indent , name, func, indent ) ;
181
182
}
182
183
builder. edit_file ( file) ;
183
184
match ctx. config . snippet_cap {
@@ -307,7 +308,7 @@ impl FunctionBuilder {
307
308
} )
308
309
}
309
310
310
- fn render ( self ) -> FunctionTemplate {
311
+ fn render ( self , is_method : bool ) -> FunctionTemplate {
311
312
let placeholder_expr = make:: ext:: expr_todo ( ) ;
312
313
let fn_body = make:: block_expr ( vec ! [ ] , Some ( placeholder_expr) ) ;
313
314
let visibility = if self . needs_pub { Some ( make:: visibility_pub_crate ( ) ) } else { None } ;
@@ -325,8 +326,14 @@ impl FunctionBuilder {
325
326
326
327
match self . target {
327
328
GeneratedFunctionTarget :: BehindItem ( it) => {
328
- let indent = IndentLevel :: from_node ( & it) ;
329
- leading_ws = format ! ( "\n \n {}" , indent) ;
329
+ let mut indent = IndentLevel :: from_node ( & it) ;
330
+ if is_method {
331
+ indent = indent + 1 ;
332
+ leading_ws = format ! ( "{}" , indent) ;
333
+ } else {
334
+ leading_ws = format ! ( "\n \n {}" , indent) ;
335
+ }
336
+
330
337
fn_def = fn_def. indent ( indent) ;
331
338
trailing_ws = String :: new ( ) ;
332
339
}
@@ -1470,11 +1477,9 @@ fn foo() {S.bar$0();}
1470
1477
struct S;
1471
1478
fn foo() {S.bar();}
1472
1479
impl S {
1473
-
1474
-
1475
- fn bar(&self) ${0:-> _} {
1476
- todo!()
1477
- }
1480
+ fn bar(&self) ${0:-> _} {
1481
+ todo!()
1482
+ }
1478
1483
}
1479
1484
" ,
1480
1485
)
@@ -1516,14 +1521,12 @@ fn foo() {s::S.bar$0();}
1516
1521
r"
1517
1522
mod s {
1518
1523
pub struct S;
1519
- impl S {
1520
-
1521
-
1522
- pub(crate) fn bar(&self) ${0:-> _} {
1523
- todo!()
1524
+ impl S {
1525
+ pub(crate) fn bar(&self) ${0:-> _} {
1526
+ todo!()
1527
+ }
1524
1528
}
1525
1529
}
1526
- }
1527
1530
fn foo() {s::S.bar();}
1528
1531
" ,
1529
1532
)
@@ -1550,11 +1553,9 @@ mod s {
1550
1553
}
1551
1554
}
1552
1555
impl S {
1553
-
1554
-
1555
- fn bar(&self) ${0:-> _} {
1556
- todo!()
1557
- }
1556
+ fn bar(&self) ${0:-> _} {
1557
+ todo!()
1558
+ }
1558
1559
}
1559
1560
1560
1561
" ,
@@ -1573,11 +1574,9 @@ fn foo() {$0S.bar();}
1573
1574
struct S;
1574
1575
fn foo() {S.bar();}
1575
1576
impl S {
1576
-
1577
-
1578
- fn bar(&self) ${0:-> _} {
1579
- todo!()
1580
- }
1577
+ fn bar(&self) ${0:-> _} {
1578
+ todo!()
1579
+ }
1581
1580
}
1582
1581
" ,
1583
1582
)
@@ -1595,11 +1594,9 @@ fn foo() {S::bar$0();}
1595
1594
struct S;
1596
1595
fn foo() {S::bar();}
1597
1596
impl S {
1598
-
1599
-
1600
- fn bar() ${0:-> _} {
1601
- todo!()
1602
- }
1597
+ fn bar() ${0:-> _} {
1598
+ todo!()
1599
+ }
1603
1600
}
1604
1601
" ,
1605
1602
)
@@ -1641,14 +1638,12 @@ fn foo() {s::S::bar$0();}
1641
1638
r"
1642
1639
mod s {
1643
1640
pub struct S;
1644
- impl S {
1645
-
1646
-
1647
- pub(crate) fn bar() ${0:-> _} {
1648
- todo!()
1641
+ impl S {
1642
+ pub(crate) fn bar() ${0:-> _} {
1643
+ todo!()
1644
+ }
1649
1645
}
1650
1646
}
1651
- }
1652
1647
fn foo() {s::S::bar();}
1653
1648
" ,
1654
1649
)
@@ -1666,11 +1661,9 @@ fn foo() {$0S::bar();}
1666
1661
struct S;
1667
1662
fn foo() {S::bar();}
1668
1663
impl S {
1669
-
1670
-
1671
- fn bar() ${0:-> _} {
1672
- todo!()
1673
- }
1664
+ fn bar() ${0:-> _} {
1665
+ todo!()
1666
+ }
1674
1667
}
1675
1668
" ,
1676
1669
)
@@ -1845,11 +1838,9 @@ fn main() {
1845
1838
Foo::new();
1846
1839
}
1847
1840
impl Foo {
1848
-
1849
-
1850
- fn new() ${0:-> _} {
1851
- todo!()
1852
- }
1841
+ fn new() ${0:-> _} {
1842
+ todo!()
1843
+ }
1853
1844
}
1854
1845
" ,
1855
1846
)
0 commit comments