@@ -82,25 +82,37 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
82
82
let no_vis_qualifiers = ctx. qualifier_ctx . vis_node . is_none ( ) ;
83
83
let in_block = kind. is_none ( ) ;
84
84
85
+ let missing_qualifiers = [
86
+ ctx. qualifier_ctx . unsafe_tok . is_none ( ) . then_some ( ( "unsafe" , "unsafe $0" ) ) ,
87
+ ctx. qualifier_ctx . async_tok . is_none ( ) . then_some ( ( "async" , "async $0" ) ) ,
88
+ ] ;
89
+
85
90
if !in_trait_impl {
86
- if ctx. qualifier_ctx . unsafe_tok . is_some ( ) {
91
+ // handle qualifier tokens
92
+ if missing_qualifiers. iter ( ) . any ( Option :: is_none) {
93
+ // only complete missing qualifiers
94
+ missing_qualifiers. iter ( ) . filter_map ( |x| * x) . for_each ( |( kw, snippet) | {
95
+ add_keyword ( kw, snippet) ;
96
+ } ) ;
97
+
87
98
if in_item_list || in_assoc_non_trait_impl {
88
99
add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
89
100
}
90
- if in_item_list {
101
+
102
+ if ctx. qualifier_ctx . unsafe_tok . is_some ( ) && in_item_list {
91
103
add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
92
104
if no_vis_qualifiers {
93
105
add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
94
106
}
95
107
}
108
+
96
109
return ;
97
110
}
98
111
99
112
if in_item_list {
100
113
add_keyword ( "enum" , "enum $1 {\n $0\n }" ) ;
101
114
add_keyword ( "mod" , "mod $0" ) ;
102
115
add_keyword ( "static" , "static $0" ) ;
103
- add_keyword ( "async" , "async $0" ) ;
104
116
add_keyword ( "struct" , "struct $0" ) ;
105
117
add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
106
118
add_keyword ( "union" , "union $1 {\n $0\n }" ) ;
@@ -129,6 +141,7 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
129
141
add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
130
142
add_keyword ( "unsafe" , "unsafe $0" ) ;
131
143
add_keyword ( "const" , "const $0" ) ;
144
+ add_keyword ( "async" , "async $0" ) ;
132
145
}
133
146
}
134
147
}
0 commit comments