@@ -9,32 +9,30 @@ use crate::{CompletionContext, CompletionItem, CompletionItemKind, CompletionKin
9
9
pub ( crate ) fn complete_use_tree_keyword ( acc : & mut Completions , ctx : & CompletionContext ) {
10
10
// complete keyword "crate" in use stmt
11
11
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
+ } ;
12
17
13
18
if ctx. use_item_syntax . is_some ( ) {
14
19
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) ;
18
21
}
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) ;
22
23
if iter:: successors ( ctx. path_qual . clone ( ) , |p| p. qualifier ( ) )
23
24
. all ( |p| p. segment ( ) . and_then ( |s| s. super_token ( ) ) . is_some ( ) )
24
25
{
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) ;
28
27
}
29
28
}
30
29
31
30
// Suggest .await syntax for types that implement Future trait
32
31
if let Some ( receiver) = & ctx. dot_receiver {
33
32
if let Some ( ty) = ctx. sema . type_of_expr ( receiver) {
34
33
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" ) ;
38
36
item. add_to ( acc) ;
39
37
}
40
38
} ;
0 commit comments