@@ -32,74 +32,11 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
3232 _ => return ,
3333 } ;
3434
35- let in_item_list = matches ! ( kind, Some ( ItemListKind :: SourceFile | ItemListKind :: Module ) | None ) ;
36- let in_assoc_non_trait_impl = matches ! ( kind, Some ( ItemListKind :: Impl | ItemListKind :: Trait ) ) ;
37- let in_extern_block = matches ! ( kind, Some ( ItemListKind :: ExternBlock ) ) ;
38- let in_trait = matches ! ( kind, Some ( ItemListKind :: Trait ) ) ;
39- let in_trait_impl = matches ! ( kind, Some ( ItemListKind :: TraitImpl ) ) ;
40- let in_inherent_impl = matches ! ( kind, Some ( ItemListKind :: Impl ) ) ;
41- let no_qualifiers = ctx. qualifier_ctx . vis_node . is_none ( ) ;
42- let in_block = matches ! ( kind, None ) ;
43-
44- if in_trait_impl {
35+ if matches ! ( kind, Some ( ItemListKind :: TraitImpl ) ) {
4536 trait_impl:: complete_trait_impl ( acc, ctx) ;
4637 }
47- let mut add_keyword = |kw, snippet| acc. add_keyword_snippet ( ctx, kw, snippet) ;
48-
49- ' block: loop {
50- if ctx. is_non_trivial_path ( ) {
51- break ' block;
52- }
53- if !in_trait_impl {
54- if ctx. qualifier_ctx . unsafe_tok . is_some ( ) {
55- if in_item_list || in_assoc_non_trait_impl {
56- add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
57- }
58- if in_item_list {
59- add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
60- if no_qualifiers {
61- add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
62- }
63- }
64- break ' block;
65- }
66-
67- if in_item_list {
68- add_keyword ( "enum" , "enum $1 {\n $0\n }" ) ;
69- add_keyword ( "mod" , "mod $0" ) ;
70- add_keyword ( "static" , "static $0" ) ;
71- add_keyword ( "struct" , "struct $0" ) ;
72- add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
73- add_keyword ( "union" , "union $1 {\n $0\n }" ) ;
74- add_keyword ( "use" , "use $0" ) ;
75- if no_qualifiers {
76- add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
77- }
78- }
7938
80- if !in_trait && !in_block && no_qualifiers {
81- add_keyword ( "pub(crate)" , "pub(crate)" ) ;
82- add_keyword ( "pub(super)" , "pub(super)" ) ;
83- add_keyword ( "pub" , "pub" ) ;
84- }
85-
86- if in_extern_block {
87- add_keyword ( "fn" , "fn $1($2);" ) ;
88- } else {
89- if !in_inherent_impl {
90- if !in_trait {
91- add_keyword ( "extern" , "extern $0" ) ;
92- }
93- add_keyword ( "type" , "type $0" ) ;
94- }
95-
96- add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
97- add_keyword ( "unsafe" , "unsafe" ) ;
98- add_keyword ( "const" , "const $0" ) ;
99- }
100- }
101- break ' block;
102- }
39+ add_keywords ( acc, ctx, kind) ;
10340
10441 if kind. is_none ( ) {
10542 // this is already handled by expression
@@ -132,3 +69,68 @@ pub(crate) fn complete_item_list(acc: &mut Completions, ctx: &CompletionContext)
13269 None => { }
13370 }
13471}
72+
73+ fn add_keywords ( acc : & mut Completions , ctx : & CompletionContext , kind : Option < & ItemListKind > ) {
74+ if ctx. is_non_trivial_path ( ) {
75+ return ;
76+ }
77+ let mut add_keyword = |kw, snippet| acc. add_keyword_snippet ( ctx, kw, snippet) ;
78+
79+ let in_item_list = matches ! ( kind, Some ( ItemListKind :: SourceFile | ItemListKind :: Module ) | None ) ;
80+ let in_assoc_non_trait_impl = matches ! ( kind, Some ( ItemListKind :: Impl | ItemListKind :: Trait ) ) ;
81+ let in_extern_block = matches ! ( kind, Some ( ItemListKind :: ExternBlock ) ) ;
82+ let in_trait = matches ! ( kind, Some ( ItemListKind :: Trait ) ) ;
83+ let in_trait_impl = matches ! ( kind, Some ( ItemListKind :: TraitImpl ) ) ;
84+ let in_inherent_impl = matches ! ( kind, Some ( ItemListKind :: Impl ) ) ;
85+ let no_qualifiers = ctx. qualifier_ctx . vis_node . is_none ( ) ;
86+ let in_block = matches ! ( kind, None ) ;
87+
88+ if !in_trait_impl {
89+ if ctx. qualifier_ctx . unsafe_tok . is_some ( ) {
90+ if in_item_list || in_assoc_non_trait_impl {
91+ add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
92+ }
93+ if in_item_list {
94+ add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
95+ if no_qualifiers {
96+ add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
97+ }
98+ }
99+ return ;
100+ }
101+
102+ if in_item_list {
103+ add_keyword ( "enum" , "enum $1 {\n $0\n }" ) ;
104+ add_keyword ( "mod" , "mod $0" ) ;
105+ add_keyword ( "static" , "static $0" ) ;
106+ add_keyword ( "struct" , "struct $0" ) ;
107+ add_keyword ( "trait" , "trait $1 {\n $0\n }" ) ;
108+ add_keyword ( "union" , "union $1 {\n $0\n }" ) ;
109+ add_keyword ( "use" , "use $0" ) ;
110+ if no_qualifiers {
111+ add_keyword ( "impl" , "impl $1 {\n $0\n }" ) ;
112+ }
113+ }
114+
115+ if !in_trait && !in_block && no_qualifiers {
116+ add_keyword ( "pub(crate)" , "pub(crate)" ) ;
117+ add_keyword ( "pub(super)" , "pub(super)" ) ;
118+ add_keyword ( "pub" , "pub" ) ;
119+ }
120+
121+ if in_extern_block {
122+ add_keyword ( "fn" , "fn $1($2);" ) ;
123+ } else {
124+ if !in_inherent_impl {
125+ if !in_trait {
126+ add_keyword ( "extern" , "extern $0" ) ;
127+ }
128+ add_keyword ( "type" , "type $0" ) ;
129+ }
130+
131+ add_keyword ( "fn" , "fn $1($2) {\n $0\n }" ) ;
132+ add_keyword ( "unsafe" , "unsafe" ) ;
133+ add_keyword ( "const" , "const $0" ) ;
134+ }
135+ }
136+ }
0 commit comments