@@ -175,12 +175,6 @@ pub(crate) fn completion_item(
175
175
line_index : & LineIndex ,
176
176
item : CompletionItem ,
177
177
) -> Vec < lsp_types:: CompletionItem > {
178
- fn set_score ( lsp_item : & mut lsp_types:: CompletionItem , label : & str ) {
179
- lsp_item. preselect = Some ( true ) ;
180
- // HACK: sort preselect items first
181
- lsp_item. sort_text = Some ( format ! ( " {}" , label) ) ;
182
- }
183
-
184
178
let mut additional_text_edits = Vec :: new ( ) ;
185
179
let mut text_edit = None ;
186
180
// LSP does not allow arbitrary edits in completion, so we have to do a
@@ -220,7 +214,9 @@ pub(crate) fn completion_item(
220
214
} ;
221
215
222
216
if item. score ( ) . is_some ( ) {
223
- set_score ( & mut lsp_item, item. label ( ) ) ;
217
+ lsp_item. preselect = Some ( true ) ;
218
+ // HACK: sort preselect items first
219
+ lsp_item. sort_text = Some ( format ! ( " {}" , item. label( ) ) ) ;
224
220
}
225
221
226
222
if item. deprecated ( ) {
@@ -233,11 +229,16 @@ pub(crate) fn completion_item(
233
229
234
230
let mut res = match item. ref_match ( ) {
235
231
Some ( mutability) => {
236
- let mut refed = lsp_item. clone ( ) ;
237
- let label = format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , refed. label) ;
238
- set_score ( & mut refed, & label) ;
239
- refed. label = label;
240
- vec ! [ lsp_item, refed]
232
+ let mut lsp_item_with_ref = lsp_item. clone ( ) ;
233
+ lsp_item. preselect = Some ( true ) ;
234
+ lsp_item. sort_text = Some ( format ! ( " {}" , item. label( ) ) ) ;
235
+ lsp_item_with_ref. label =
236
+ format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , lsp_item_with_ref. label) ;
237
+ if let Some ( lsp_types:: CompletionTextEdit :: Edit ( it) ) = & mut lsp_item_with_ref. text_edit
238
+ {
239
+ it. new_text = format ! ( "&{}{}" , mutability. as_keyword_for_ref( ) , it. new_text) ;
240
+ }
241
+ vec ! [ lsp_item_with_ref, lsp_item]
241
242
}
242
243
None => vec ! [ lsp_item] ,
243
244
} ;
@@ -1104,13 +1105,13 @@ mod tests {
1104
1105
expect_test:: expect![ [ r#"
1105
1106
[
1106
1107
(
1107
- "arg",
1108
+ "& arg",
1108
1109
None,
1109
1110
),
1110
1111
(
1111
- "& arg",
1112
+ "arg",
1112
1113
Some(
1113
- " & arg",
1114
+ " arg",
1114
1115
),
1115
1116
),
1116
1117
]
0 commit comments