@@ -29,7 +29,9 @@ pub(crate) fn complete_item_list(
2929 kind : & ItemListKind ,
3030) {
3131 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 ( _) ) {
3335 add_keywords ( acc, ctx, Some ( kind) ) ;
3436 }
3537
@@ -81,7 +83,6 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
8183 matches ! ( kind, Some ( ItemListKind :: ExternBlock { is_unsafe: true } ) ) ;
8284
8385 let in_trait = matches ! ( kind, Some ( ItemListKind :: Trait ) ) ;
84- let in_trait_impl = matches ! ( kind, Some ( ItemListKind :: TraitImpl ( _) ) ) ;
8586 let in_inherent_impl = matches ! ( kind, Some ( ItemListKind :: Impl ) ) ;
8687 let in_block = kind. is_none ( ) ;
8788
@@ -90,38 +91,34 @@ fn add_keywords(acc: &mut Completions, ctx: &CompletionContext<'_>, kind: Option
9091 let has_async_kw = ctx. qualifier_ctx . async_tok . is_some ( ) ;
9192 let has_safe_kw = ctx. qualifier_ctx . safe_tok . is_some ( ) ;
9293
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;" ) ;
9598 return ;
9699 }
97100
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+ }
110108
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+ }
114112
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 }" ) ;
120117 }
118+ }
121119
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" ) ;
125122 }
126123
127124 return ;
0 commit comments