@@ -90,32 +90,34 @@ pub enum AdjustmentHintsMode {
90
90
PreferPostfix ,
91
91
}
92
92
93
- // FIXME: Clean up this mess, the kinds are mainly used for setting different rendering properties in the lsp layer
94
- // We should probably turns this into such a property holding struct. Or clean this up in some other form.
95
93
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
96
94
pub enum InlayKind {
95
+ Adjustment ,
97
96
BindingMode ,
98
97
Chaining ,
99
98
ClosingBrace ,
100
- ClosureReturnType ,
99
+ ClosureCapture ,
100
+ Discriminant ,
101
101
GenericParamList ,
102
- Adjustment ,
103
- AdjustmentPostfix ,
104
102
Lifetime ,
105
- ClosureCapture ,
106
103
Parameter ,
107
104
Type ,
108
- Discriminant ,
109
- OpeningParenthesis ,
110
- ClosingParenthesis ,
105
+ }
106
+
107
+ #[ derive( Debug ) ]
108
+ pub enum InlayHintPosition {
109
+ Before ,
110
+ After ,
111
111
}
112
112
113
113
#[ derive( Debug ) ]
114
114
pub struct InlayHint {
115
115
/// The text range this inlay hint applies to.
116
116
pub range : TextRange ,
117
- /// The kind of this inlay hint. This is used to determine side and padding of the hint for
118
- /// rendering purposes.
117
+ pub position : InlayHintPosition ,
118
+ pub pad_left : bool ,
119
+ pub pad_right : bool ,
120
+ /// The kind of this inlay hint.
119
121
pub kind : InlayKind ,
120
122
/// The actual label to show in the inlay hint.
121
123
pub label : InlayHintLabel ,
@@ -124,20 +126,26 @@ pub struct InlayHint {
124
126
}
125
127
126
128
impl InlayHint {
127
- fn closing_paren ( range : TextRange ) -> InlayHint {
129
+ fn closing_paren_after ( kind : InlayKind , range : TextRange ) -> InlayHint {
128
130
InlayHint {
129
131
range,
130
- kind : InlayKind :: ClosingParenthesis ,
132
+ kind,
131
133
label : InlayHintLabel :: from ( ")" ) ,
132
134
text_edit : None ,
135
+ position : InlayHintPosition :: After ,
136
+ pad_left : false ,
137
+ pad_right : false ,
133
138
}
134
139
}
135
- fn opening_paren ( range : TextRange ) -> InlayHint {
140
+ fn opening_paren_before ( kind : InlayKind , range : TextRange ) -> InlayHint {
136
141
InlayHint {
137
142
range,
138
- kind : InlayKind :: OpeningParenthesis ,
143
+ kind,
139
144
label : InlayHintLabel :: from ( "(" ) ,
140
145
text_edit : None ,
146
+ position : InlayHintPosition :: Before ,
147
+ pad_left : false ,
148
+ pad_right : false ,
141
149
}
142
150
}
143
151
}
@@ -303,13 +311,13 @@ impl InlayHintLabelBuilder<'_> {
303
311
fn label_of_ty (
304
312
famous_defs @ FamousDefs ( sema, _) : & FamousDefs < ' _ , ' _ > ,
305
313
config : & InlayHintsConfig ,
306
- ty : hir:: Type ,
314
+ ty : & hir:: Type ,
307
315
) -> Option < InlayHintLabel > {
308
316
fn rec (
309
317
sema : & Semantics < ' _ , RootDatabase > ,
310
318
famous_defs : & FamousDefs < ' _ , ' _ > ,
311
319
mut max_length : Option < usize > ,
312
- ty : hir:: Type ,
320
+ ty : & hir:: Type ,
313
321
label_builder : & mut InlayHintLabelBuilder < ' _ > ,
314
322
config : & InlayHintsConfig ,
315
323
) -> Result < ( ) , HirDisplayError > {
@@ -342,7 +350,7 @@ fn label_of_ty(
342
350
label_builder. write_str ( LABEL_ITEM ) ?;
343
351
label_builder. end_location_link ( ) ;
344
352
label_builder. write_str ( LABEL_MIDDLE2 ) ?;
345
- rec ( sema, famous_defs, max_length, ty, label_builder, config) ?;
353
+ rec ( sema, famous_defs, max_length, & ty, label_builder, config) ?;
346
354
label_builder. write_str ( LABEL_END ) ?;
347
355
Ok ( ( ) )
348
356
}
@@ -574,7 +582,8 @@ mod tests {
574
582
let inlay_hints = analysis. inlay_hints ( & config, file_id, None ) . unwrap ( ) ;
575
583
let actual = inlay_hints
576
584
. into_iter ( )
577
- . map ( |it| ( it. range , it. label . to_string ( ) ) )
585
+ // FIXME: We trim the start because some inlay produces leading whitespace which is not properly supported by our annotation extraction
586
+ . map ( |it| ( it. range , it. label . to_string ( ) . trim_start ( ) . to_owned ( ) ) )
578
587
. sorted_by_key ( |( range, _) | range. start ( ) )
579
588
. collect :: < Vec < _ > > ( ) ;
580
589
expected. sort_by_key ( |( range, _) | range. start ( ) ) ;
0 commit comments