@@ -9,6 +9,7 @@ use ide_db::famous_defs::FamousDefs;
99
1010use span:: EditionedFileId ;
1111use syntax:: ast:: { self , AstNode } ;
12+ use text_edit:: TextEditBuilder ;
1213
1314use crate :: { InlayHint , InlayHintLabel , InlayHintPosition , InlayHintsConfig , InlayKind } ;
1415
@@ -61,40 +62,55 @@ pub(super) fn hints(
6162 hint. label . append_str ( r) ;
6263 } ) ;
6364 hint. pad_right = was_mut_last;
64- if !hint. label . parts . is_empty ( ) {
65- acc. push ( hint) ;
66- }
65+ let acc_base = acc. len ( ) ;
6766 match pat {
6867 ast:: Pat :: IdentPat ( pat) if pat. ref_token ( ) . is_none ( ) && pat. mut_token ( ) . is_none ( ) => {
6968 let bm = sema. binding_mode_of_pat ( pat) ?;
7069 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" ) ,
7473 } ;
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+ }
8586 }
8687 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 ( "(" ) ;
9189 acc. push ( InlayHint :: closing_paren_after (
9290 InlayKind :: BindingMode ,
9391 pat. syntax ( ) . text_range ( ) ,
9492 ) ) ;
9593 }
9694 _ => ( ) ,
9795 }
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+ }
98114
99115 Some ( ( ) )
100116}
@@ -145,11 +161,10 @@ fn __(
145161 }
146162 match &(0,) {
147163 (x,) | (x,) => (),
148- //^^^^^^^^^^^&
164+ //^^^^^^^^^^^)
165+ //^^^^^^^^^^^&(
149166 //^ ref
150167 //^ ref
151- //^^^^^^^^^^^(
152- //^^^^^^^^^^^)
153168 ((x,) | (x,)) => (),
154169 //^^^^^^^^^^^^^&
155170 //^ ref
0 commit comments