@@ -9,6 +9,7 @@ use ide_db::famous_defs::FamousDefs;
9
9
10
10
use span:: EditionedFileId ;
11
11
use syntax:: ast:: { self , AstNode } ;
12
+ use text_edit:: TextEditBuilder ;
12
13
13
14
use crate :: { InlayHint , InlayHintLabel , InlayHintPosition , InlayHintsConfig , InlayKind } ;
14
15
@@ -61,40 +62,55 @@ pub(super) fn hints(
61
62
hint. label . append_str ( r) ;
62
63
} ) ;
63
64
hint. pad_right = was_mut_last;
64
- if !hint. label . parts . is_empty ( ) {
65
- acc. push ( hint) ;
66
- }
65
+ let acc_base = acc. len ( ) ;
67
66
match pat {
68
67
ast:: Pat :: IdentPat ( pat) if pat. ref_token ( ) . is_none ( ) && pat. mut_token ( ) . is_none ( ) => {
69
68
let bm = sema. binding_mode_of_pat ( pat) ?;
70
69
let bm = match bm {
71
- hir:: BindingMode :: Move => return None ,
72
- hir:: BindingMode :: Ref ( Mutability :: Mut ) => "ref mut" ,
73
- hir:: BindingMode :: Ref ( Mutability :: Shared ) => "ref" ,
70
+ hir:: BindingMode :: Move => None ,
71
+ hir:: BindingMode :: Ref ( Mutability :: Mut ) => Some ( "ref mut" ) ,
72
+ hir:: BindingMode :: Ref ( Mutability :: Shared ) => Some ( "ref" ) ,
74
73
} ;
75
- acc. push ( InlayHint {
76
- range : pat. syntax ( ) . text_range ( ) ,
77
- kind : InlayKind :: BindingMode ,
78
- label : bm. into ( ) ,
79
- text_edit : None ,
80
- position : InlayHintPosition :: Before ,
81
- pad_left : false ,
82
- pad_right : true ,
83
- resolve_parent : Some ( pat. syntax ( ) . text_range ( ) ) ,
84
- } ) ;
74
+ if let Some ( bm) = bm {
75
+ acc. push ( InlayHint {
76
+ range : pat. syntax ( ) . text_range ( ) ,
77
+ kind : InlayKind :: BindingMode ,
78
+ label : bm. into ( ) ,
79
+ text_edit : None ,
80
+ position : InlayHintPosition :: Before ,
81
+ pad_left : false ,
82
+ pad_right : true ,
83
+ resolve_parent : Some ( pat. syntax ( ) . text_range ( ) ) ,
84
+ } ) ;
85
+ }
85
86
}
86
87
ast:: Pat :: OrPat ( pat) if !pattern_adjustments. is_empty ( ) && outer_paren_pat. is_none ( ) => {
87
- acc. push ( InlayHint :: opening_paren_before (
88
- InlayKind :: BindingMode ,
89
- pat. syntax ( ) . text_range ( ) ,
90
- ) ) ;
88
+ hint. label . append_str ( "(" ) ;
91
89
acc. push ( InlayHint :: closing_paren_after (
92
90
InlayKind :: BindingMode ,
93
91
pat. syntax ( ) . text_range ( ) ,
94
92
) ) ;
95
93
}
96
94
_ => ( ) ,
97
95
}
96
+ if !hint. label . parts . is_empty ( ) {
97
+ acc. push ( hint) ;
98
+ }
99
+
100
+ if let hints @ [ _, ..] = & mut acc[ acc_base..] {
101
+ let mut edit = TextEditBuilder :: default ( ) ;
102
+ for h in & mut * hints {
103
+ edit. insert (
104
+ match h. position {
105
+ InlayHintPosition :: Before => h. range . start ( ) ,
106
+ InlayHintPosition :: After => h. range . end ( ) ,
107
+ } ,
108
+ h. label . parts . iter ( ) . map ( |p| & * p. text ) . collect ( ) ,
109
+ ) ;
110
+ }
111
+ let edit = edit. finish ( ) ;
112
+ hints. iter_mut ( ) . for_each ( |h| h. text_edit = Some ( edit. clone ( ) ) ) ;
113
+ }
98
114
99
115
Some ( ( ) )
100
116
}
@@ -145,11 +161,10 @@ fn __(
145
161
}
146
162
match &(0,) {
147
163
(x,) | (x,) => (),
148
- //^^^^^^^^^^^&
164
+ //^^^^^^^^^^^)
165
+ //^^^^^^^^^^^&(
149
166
//^ ref
150
167
//^ ref
151
- //^^^^^^^^^^^(
152
- //^^^^^^^^^^^)
153
168
((x,) | (x,)) => (),
154
169
//^^^^^^^^^^^^^&
155
170
//^ ref
0 commit comments