@@ -6,6 +6,7 @@ use ide_db::{
6
6
source_change:: SourceChangeBuilder ,
7
7
} ;
8
8
use syntax:: ToSmolStr ;
9
+ use syntax:: ast:: edit:: AstNodeEdit ;
9
10
10
11
use crate :: { Diagnostic , DiagnosticCode , DiagnosticsContext } ;
11
12
@@ -23,33 +24,32 @@ pub(crate) fn trait_impl_redundant_assoc_item(
23
24
24
25
let default_range = d. impl_ . syntax_node_ptr ( ) . text_range ( ) ;
25
26
let trait_name = d. trait_ . name ( db) . display_no_db ( ctx. edition ) . to_smolstr ( ) ;
27
+ let indent_level = d. trait_ . source ( db) . map_or ( 0 , |it| it. value . indent_level ( ) . 0 ) + 1 ;
26
28
27
29
let ( redundant_item_name, diagnostic_range, redundant_item_def) = match assoc_item {
28
30
hir:: AssocItem :: Function ( id) => {
29
31
let function = id;
30
32
(
31
33
format ! ( "`fn {redundant_assoc_item_name}`" ) ,
32
34
function. source ( db) . map ( |it| it. syntax ( ) . text_range ( ) ) . unwrap_or ( default_range) ,
33
- format ! ( "\n {};" , function. display( db, ctx. display_target) ) ,
35
+ format ! ( "\n {};" , function. display( db, ctx. display_target) ) ,
34
36
)
35
37
}
36
38
hir:: AssocItem :: Const ( id) => {
37
39
let constant = id;
38
40
(
39
41
format ! ( "`const {redundant_assoc_item_name}`" ) ,
40
42
constant. source ( db) . map ( |it| it. syntax ( ) . text_range ( ) ) . unwrap_or ( default_range) ,
41
- format ! ( "\n {};" , constant. display( db, ctx. display_target) ) ,
43
+ format ! ( "\n {};" , constant. display( db, ctx. display_target) ) ,
42
44
)
43
45
}
44
46
hir:: AssocItem :: TypeAlias ( id) => {
45
47
let type_alias = id;
46
48
(
47
49
format ! ( "`type {redundant_assoc_item_name}`" ) ,
48
50
type_alias. source ( db) . map ( |it| it. syntax ( ) . text_range ( ) ) . unwrap_or ( default_range) ,
49
- format ! (
50
- "\n type {};" ,
51
- type_alias. name( ctx. sema. db) . display_no_db( ctx. edition) . to_smolstr( )
52
- ) ,
51
+ // FIXME cannot generate generic parameter and bounds
52
+ format ! ( "\n type {};" , type_alias. name( ctx. sema. db) . display_no_db( ctx. edition) ) ,
53
53
)
54
54
}
55
55
} ;
@@ -65,7 +65,7 @@ pub(crate) fn trait_impl_redundant_assoc_item(
65
65
. with_fixes ( quickfix_for_redundant_assoc_item (
66
66
ctx,
67
67
d,
68
- redundant_item_def,
68
+ stdx :: indent_string ( redundant_item_def, indent_level ) . into ( ) ,
69
69
diagnostic_range,
70
70
) )
71
71
}
@@ -191,6 +191,89 @@ impl Marker for Foo {
191
191
)
192
192
}
193
193
194
+ #[ test]
195
+ fn quickfix_indentations ( ) {
196
+ check_fix (
197
+ r#"
198
+ mod indent {
199
+ trait Marker {
200
+ fn boo();
201
+ }
202
+ struct Foo;
203
+ impl Marker for Foo {
204
+ fn$0 bar<T: Copy>(_a: i32, _b: T) -> String {}
205
+ fn boo() {}
206
+ }
207
+ }
208
+ "# ,
209
+ r#"
210
+ mod indent {
211
+ trait Marker {
212
+ fn bar<T>(_a: i32, _b: T) -> String
213
+ where
214
+ T: Copy,;
215
+ fn boo();
216
+ }
217
+ struct Foo;
218
+ impl Marker for Foo {
219
+ fn bar<T: Copy>(_a: i32, _b: T) -> String {}
220
+ fn boo() {}
221
+ }
222
+ }
223
+ "# ,
224
+ ) ;
225
+
226
+ check_fix (
227
+ r#"
228
+ mod indent {
229
+ trait Marker {
230
+ fn foo () {}
231
+ }
232
+ struct Foo;
233
+ impl Marker for Foo {
234
+ const FLAG: bool$0 = false;
235
+ }
236
+ }
237
+ "# ,
238
+ r#"
239
+ mod indent {
240
+ trait Marker {
241
+ const FLAG: bool;
242
+ fn foo () {}
243
+ }
244
+ struct Foo;
245
+ impl Marker for Foo {
246
+ const FLAG: bool = false;
247
+ }
248
+ }
249
+ "# ,
250
+ ) ;
251
+
252
+ check_fix (
253
+ r#"
254
+ mod indent {
255
+ trait Marker {
256
+ }
257
+ struct Foo;
258
+ impl Marker for Foo {
259
+ type T = i32;$0
260
+ }
261
+ }
262
+ "# ,
263
+ r#"
264
+ mod indent {
265
+ trait Marker {
266
+ type T;
267
+ }
268
+ struct Foo;
269
+ impl Marker for Foo {
270
+ type T = i32;
271
+ }
272
+ }
273
+ "# ,
274
+ ) ;
275
+ }
276
+
194
277
#[ test]
195
278
fn quickfix_dont_work ( ) {
196
279
check_no_fix (
0 commit comments