@@ -9,14 +9,9 @@ use ra_syntax::{
9
9
SmolStr , SyntaxKind , SyntaxNode , TextRange ,
10
10
} ;
11
11
12
- #[ derive( Debug , PartialEq , Eq , Clone ) ]
12
+ #[ derive( Debug , PartialEq , Eq ) ]
13
13
pub enum InlayKind {
14
- LetBindingType ,
15
- ClosureParameterType ,
16
- ForExpressionBindingType ,
17
- IfExpressionType ,
18
- WhileLetExpressionType ,
19
- MatchArmType ,
14
+ TypeHint ,
20
15
}
21
16
22
17
#[ derive( Debug ) ]
@@ -46,7 +41,7 @@ fn get_inlay_hints(
46
41
}
47
42
let pat = let_statement. pat ( ) ?;
48
43
let analyzer = SourceAnalyzer :: new ( db, file_id, let_statement. syntax ( ) , None ) ;
49
- Some ( get_pat_hints ( db, & analyzer, pat, InlayKind :: LetBindingType , false ) )
44
+ Some ( get_pat_type_hints ( db, & analyzer, pat, false ) )
50
45
} )
51
46
. visit ( |closure_parameter : LambdaExpr | {
52
47
let analyzer = SourceAnalyzer :: new ( db, file_id, closure_parameter. syntax ( ) , None ) ;
@@ -55,33 +50,25 @@ fn get_inlay_hints(
55
50
. params ( )
56
51
. filter ( |closure_param| closure_param. ascribed_type ( ) . is_none ( ) )
57
52
. filter_map ( |closure_param| closure_param. pat ( ) )
58
- . map ( |root_pat| {
59
- get_pat_hints (
60
- db,
61
- & analyzer,
62
- root_pat,
63
- InlayKind :: ClosureParameterType ,
64
- false ,
65
- )
66
- } )
53
+ . map ( |root_pat| get_pat_type_hints ( db, & analyzer, root_pat, false ) )
67
54
. flatten ( )
68
55
. collect ( )
69
56
} )
70
57
} )
71
58
. visit ( |for_expression : ForExpr | {
72
59
let pat = for_expression. pat ( ) ?;
73
60
let analyzer = SourceAnalyzer :: new ( db, file_id, for_expression. syntax ( ) , None ) ;
74
- Some ( get_pat_hints ( db, & analyzer, pat, InlayKind :: ForExpressionBindingType , false ) )
61
+ Some ( get_pat_type_hints ( db, & analyzer, pat, false ) )
75
62
} )
76
63
. visit ( |if_expr : IfExpr | {
77
64
let pat = if_expr. condition ( ) ?. pat ( ) ?;
78
65
let analyzer = SourceAnalyzer :: new ( db, file_id, if_expr. syntax ( ) , None ) ;
79
- Some ( get_pat_hints ( db, & analyzer, pat, InlayKind :: IfExpressionType , true ) )
66
+ Some ( get_pat_type_hints ( db, & analyzer, pat, true ) )
80
67
} )
81
68
. visit ( |while_expr : WhileExpr | {
82
69
let pat = while_expr. condition ( ) ?. pat ( ) ?;
83
70
let analyzer = SourceAnalyzer :: new ( db, file_id, while_expr. syntax ( ) , None ) ;
84
- Some ( get_pat_hints ( db, & analyzer, pat, InlayKind :: WhileLetExpressionType , true ) )
71
+ Some ( get_pat_type_hints ( db, & analyzer, pat, true ) )
85
72
} )
86
73
. visit ( |match_arm_list : MatchArmList | {
87
74
let analyzer = SourceAnalyzer :: new ( db, file_id, match_arm_list. syntax ( ) , None ) ;
@@ -90,21 +77,18 @@ fn get_inlay_hints(
90
77
. arms ( )
91
78
. map ( |match_arm| match_arm. pats ( ) )
92
79
. flatten ( )
93
- . map ( |root_pat| {
94
- get_pat_hints ( db, & analyzer, root_pat, InlayKind :: MatchArmType , true )
95
- } )
80
+ . map ( |root_pat| get_pat_type_hints ( db, & analyzer, root_pat, true ) )
96
81
. flatten ( )
97
82
. collect ( ) ,
98
83
)
99
84
} )
100
85
. accept ( & node) ?
101
86
}
102
87
103
- fn get_pat_hints (
88
+ fn get_pat_type_hints (
104
89
db : & RootDatabase ,
105
90
analyzer : & SourceAnalyzer ,
106
91
root_pat : Pat ,
107
- kind : InlayKind ,
108
92
skip_root_pat_hint : bool ,
109
93
) -> Vec < InlayHint > {
110
94
let original_pat = & root_pat. clone ( ) ;
@@ -118,7 +102,7 @@ fn get_pat_hints(
118
102
} )
119
103
. map ( |( range, pat_type) | InlayHint {
120
104
range,
121
- kind : kind . clone ( ) ,
105
+ kind : InlayKind :: TypeHint ,
122
106
label : pat_type. display ( db) . to_string ( ) . into ( ) ,
123
107
} )
124
108
. collect ( )
@@ -232,52 +216,52 @@ fn main() {
232
216
assert_debug_snapshot_matches ! ( analysis. inlay_hints( file_id) . unwrap( ) , @r#"[
233
217
InlayHint {
234
218
range: [193; 197),
235
- kind: LetBindingType ,
219
+ kind: TypeHint ,
236
220
label: "i32",
237
221
},
238
222
InlayHint {
239
223
range: [236; 244),
240
- kind: LetBindingType ,
224
+ kind: TypeHint ,
241
225
label: "i32",
242
226
},
243
227
InlayHint {
244
228
range: [275; 279),
245
- kind: LetBindingType ,
229
+ kind: TypeHint ,
246
230
label: "&str",
247
231
},
248
232
InlayHint {
249
233
range: [539; 543),
250
- kind: LetBindingType ,
234
+ kind: TypeHint ,
251
235
label: "(i32, char)",
252
236
},
253
237
InlayHint {
254
238
range: [566; 567),
255
- kind: LetBindingType ,
239
+ kind: TypeHint ,
256
240
label: "i32",
257
241
},
258
242
InlayHint {
259
243
range: [570; 571),
260
- kind: LetBindingType ,
244
+ kind: TypeHint ,
261
245
label: "i32",
262
246
},
263
247
InlayHint {
264
248
range: [573; 574),
265
- kind: LetBindingType ,
249
+ kind: TypeHint ,
266
250
label: "i32",
267
251
},
268
252
InlayHint {
269
253
range: [584; 585),
270
- kind: LetBindingType ,
254
+ kind: TypeHint ,
271
255
label: "i32",
272
256
},
273
257
InlayHint {
274
258
range: [577; 578),
275
- kind: LetBindingType ,
259
+ kind: TypeHint ,
276
260
label: "f64",
277
261
},
278
262
InlayHint {
279
263
range: [580; 581),
280
- kind: LetBindingType ,
264
+ kind: TypeHint ,
281
265
label: "f64",
282
266
},
283
267
]"#
@@ -299,12 +283,12 @@ fn main() {
299
283
assert_debug_snapshot_matches ! ( analysis. inlay_hints( file_id) . unwrap( ) , @r#"[
300
284
InlayHint {
301
285
range: [21; 30),
302
- kind: LetBindingType ,
286
+ kind: TypeHint ,
303
287
label: "i32",
304
288
},
305
289
InlayHint {
306
290
range: [57; 66),
307
- kind: ClosureParameterType ,
291
+ kind: TypeHint ,
308
292
label: "i32",
309
293
},
310
294
]"#
@@ -326,12 +310,12 @@ fn main() {
326
310
assert_debug_snapshot_matches ! ( analysis. inlay_hints( file_id) . unwrap( ) , @r#"[
327
311
InlayHint {
328
312
range: [21; 30),
329
- kind: LetBindingType ,
313
+ kind: TypeHint ,
330
314
label: "i32",
331
315
},
332
316
InlayHint {
333
317
range: [44; 53),
334
- kind: ForExpressionBindingType ,
318
+ kind: TypeHint ,
335
319
label: "i32",
336
320
},
337
321
]"#
@@ -364,35 +348,35 @@ fn main() {
364
348
if let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {};
365
349
if let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {};
366
350
if let CustomOption::Some(Test { b: y, .. }) = &test {};
367
-
351
+
368
352
if test == CustomOption::None {}
369
353
}"# ,
370
354
) ;
371
355
372
356
assert_debug_snapshot_matches ! ( analysis. inlay_hints( file_id) . unwrap( ) , @r#"[
373
357
InlayHint {
374
358
range: [166; 170),
375
- kind: LetBindingType ,
359
+ kind: TypeHint ,
376
360
label: "CustomOption<Test>",
377
361
},
378
362
InlayHint {
379
363
range: [334; 338),
380
- kind: IfExpressionType ,
364
+ kind: TypeHint ,
381
365
label: "&Test",
382
366
},
383
367
InlayHint {
384
368
range: [389; 390),
385
- kind: IfExpressionType ,
369
+ kind: TypeHint ,
386
370
label: "&CustomOption<u32>",
387
371
},
388
372
InlayHint {
389
373
range: [392; 393),
390
- kind: IfExpressionType ,
374
+ kind: TypeHint ,
391
375
label: "&u8",
392
376
},
393
377
InlayHint {
394
378
range: [531; 532),
395
- kind: IfExpressionType ,
379
+ kind: TypeHint ,
396
380
label: "&u32",
397
381
},
398
382
]"#
@@ -425,15 +409,15 @@ fn main() {
425
409
while let CustomOption::Some(Test { a: CustomOption::Some(x), b: y }) = &test {};
426
410
while let CustomOption::Some(Test { a: CustomOption::None, b: y }) = &test {};
427
411
while let CustomOption::Some(Test { b: y, .. }) = &test {};
428
-
412
+
429
413
while test == CustomOption::None {}
430
414
}"# ,
431
415
) ;
432
416
433
417
assert_debug_snapshot_matches ! ( analysis. inlay_hints( file_id) . unwrap( ) , @r#"[
434
418
InlayHint {
435
419
range: [166; 170),
436
- kind: LetBindingType ,
420
+ kind: TypeHint ,
437
421
label: "CustomOption<Test>",
438
422
},
439
423
]"#
@@ -445,7 +429,7 @@ fn main() {
445
429
let ( analysis, file_id) = single_file (
446
430
r#"
447
431
#[derive(PartialEq)]
448
- enum CustomOption<T> {
432
+ enum CustomOption<T> {
449
433
None,
450
434
Some(T),
451
435
}
@@ -473,23 +457,23 @@ fn main() {
473
457
474
458
assert_debug_snapshot_matches ! ( analysis. inlay_hints( file_id) . unwrap( ) , @r#"[
475
459
InlayHint {
476
- range: [312; 316 ),
477
- kind: MatchArmType ,
460
+ range: [311; 315 ),
461
+ kind: TypeHint ,
478
462
label: "Test",
479
463
},
480
464
InlayHint {
481
- range: [359; 360 ),
482
- kind: MatchArmType ,
465
+ range: [358; 359 ),
466
+ kind: TypeHint ,
483
467
label: "CustomOption<u32>",
484
468
},
485
469
InlayHint {
486
- range: [362; 363 ),
487
- kind: MatchArmType ,
470
+ range: [361; 362 ),
471
+ kind: TypeHint ,
488
472
label: "u8",
489
473
},
490
474
InlayHint {
491
- range: [485; 486 ),
492
- kind: MatchArmType ,
475
+ range: [484; 485 ),
476
+ kind: TypeHint ,
493
477
label: "u32",
494
478
},
495
479
]"#
0 commit comments