@@ -9,32 +9,30 @@ use crate::{CompletionContext, CompletionItem, CompletionItemKind, CompletionKin
99pub ( crate ) fn complete_use_tree_keyword ( acc : & mut Completions , ctx : & CompletionContext ) {
1010 // complete keyword "crate" in use stmt
1111 let source_range = ctx. source_range ( ) ;
12+ let kw_completion = move |text : & str | {
13+ let mut item = CompletionItem :: new ( CompletionKind :: Keyword , source_range, text) ;
14+ item. kind ( CompletionItemKind :: Keyword ) . insert_text ( text) ;
15+ item
16+ } ;
1217
1318 if ctx. use_item_syntax . is_some ( ) {
1419 if ctx. path_qual . is_none ( ) {
15- let mut item = CompletionItem :: new ( CompletionKind :: Keyword , source_range, "crate::" ) ;
16- item. kind ( CompletionItemKind :: Keyword ) . insert_text ( "crate::" ) ;
17- item. add_to ( acc) ;
20+ kw_completion ( "crate::" ) . add_to ( acc) ;
1821 }
19- let mut item = CompletionItem :: new ( CompletionKind :: Keyword , source_range, "self" ) ;
20- item. kind ( CompletionItemKind :: Keyword ) ;
21- item. add_to ( acc) ;
22+ kw_completion ( "self" ) . add_to ( acc) ;
2223 if iter:: successors ( ctx. path_qual . clone ( ) , |p| p. qualifier ( ) )
2324 . all ( |p| p. segment ( ) . and_then ( |s| s. super_token ( ) ) . is_some ( ) )
2425 {
25- let mut item = CompletionItem :: new ( CompletionKind :: Keyword , source_range, "super::" ) ;
26- item. kind ( CompletionItemKind :: Keyword ) . insert_text ( "super::" ) ;
27- item. add_to ( acc) ;
26+ kw_completion ( "super::" ) . add_to ( acc) ;
2827 }
2928 }
3029
3130 // Suggest .await syntax for types that implement Future trait
3231 if let Some ( receiver) = & ctx. dot_receiver {
3332 if let Some ( ty) = ctx. sema . type_of_expr ( receiver) {
3433 if ty. impls_future ( ctx. db ) {
35- let mut item =
36- CompletionItem :: new ( CompletionKind :: Keyword , ctx. source_range ( ) , "await" ) ;
37- item. kind ( CompletionItemKind :: Keyword ) . detail ( "expr.await" ) . insert_text ( "await" ) ;
34+ let mut item = kw_completion ( "await" ) ;
35+ item. detail ( "expr.await" ) ;
3836 item. add_to ( acc) ;
3937 }
4038 } ;
0 commit comments