@@ -29,7 +29,9 @@ pub(crate) fn complete_item_list(
29
29
kind : & ItemListKind ,
30
30
) {
31
31
let _p = tracing:: info_span!( "complete_item_list" ) . entered ( ) ;
32
- if path_ctx. is_trivial_path ( ) {
32
+
33
+ // We handle completions for trait-impls in [`item_list::trait_impl`]
34
+ if path_ctx. is_trivial_path ( ) && !matches ! ( kind, ItemListKind :: TraitImpl ( _) ) {
33
35
add_keywords ( acc, ctx, Some ( kind) ) ;
34
36
}
35
37
@@ -81,7 +83,6 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
81
83
matches ! ( kind, Some ( ItemListKind :: ExternBlock { is_unsafe: true } ) ) ;
82
84
83
85
let in_trait = matches ! ( kind, Some ( ItemListKind :: Trait ) ) ;
84
- let in_trait_impl = matches ! ( kind, Some ( ItemListKind :: TraitImpl ( _) ) ) ;
85
86
let in_inherent_impl = matches ! ( kind, Some ( ItemListKind :: Impl ) ) ;
86
87
let in_block = kind. is_none ( ) ;
87
88
@@ -90,38 +91,34 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
90
91
let has_async_kw = ctx. qualifier_ctx . async_tok . is_some ( ) ;
91
92
let has_safe_kw = ctx. qualifier_ctx . safe_tok . is_some ( ) ;
92
93
93
- // We handle completions for trait-impls in [`item_list::trait_impl`]
94
- if in_trait_impl {
94
+ // Some keywords are invalid after non-vis qualifiers, so we handle them first.
95
+ if ( has_unsafe_kw || has_safe_kw) && in_extern_block {
96
+ add_keyword ( "fn" , "fn $1($2);" ) ;
97
+ add_keyword ( "static" , "static $1: $2;" ) ;
95
98
return ;
96
99
}
97
100
98
- // Some keywords are invalid after non-vis qualifiers, so we handle them first.
99
- if has_unsafe_kw || has_async_kw || has_safe_kw {
100
- if in_extern_block {
101
- add_keyword ( "fn" , "fn $1($2);" ) ;
102
- add_keyword ( "static" , "static $1: $2;" ) ;
103
- } else {
104
- if !has_unsafe_kw {
105
- add_keyword ( "unsafe" , "unsafe $0" ) ;
106
- }
107
- if !has_async_kw {
108
- add_keyword ( "async" , "async $0" ) ;
109
- }
101
+ if has_unsafe_kw || has_async_kw {
102
+ if !has_unsafe_kw {
103
+ add_keyword ( "unsafe" , "unsafe $0" ) ;
104
+ }
105
+ if !has_async_kw {
106
+ add_keyword ( "async" , "async $0" ) ;
107
+ }
110
108
111
- if in_item_list || in_assoc_non_trait_impl {
112
- add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
113
- }
109
+ if in_item_list || in_assoc_non_trait_impl {
110
+ add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
111
+ }
114
112
115
- if has_unsafe_kw && in_item_list {
116
- add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
117
- if no_vis_qualifiers {
118
- add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
119
- }
113
+ if has_unsafe_kw && in_item_list {
114
+ add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
115
+ if no_vis_qualifiers {
116
+ add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
120
117
}
118
+ }
121
119
122
- if !has_async_kw && no_vis_qualifiers && in_item_list {
123
- add_keyword ( "extern" , "extern $0" ) ;
124
- }
120
+ if !has_async_kw && no_vis_qualifiers && in_item_list {
121
+ add_keyword ( "extern" , "extern $0" ) ;
125
122
}
126
123
127
124
return ;
0 commit comments