@@ -46,7 +46,7 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr
4646 _ => { }
4747 }
4848
49- if attribute. kind ( ) == ast:: AttrKind :: Inner || !attr_completion. should_be_inner {
49+ if attribute. kind ( ) == ast:: AttrKind :: Inner || !attr_completion. prefer_inner {
5050 acc. add ( item) ;
5151 }
5252 }
@@ -56,159 +56,72 @@ struct AttrCompletion {
5656 label : & ' static str ,
5757 lookup : Option < & ' static str > ,
5858 snippet : Option < & ' static str > ,
59- should_be_inner : bool ,
59+ prefer_inner : bool ,
60+ }
61+
62+ impl AttrCompletion {
63+ const fn prefer_inner ( self ) -> AttrCompletion {
64+ AttrCompletion { prefer_inner : true , ..self }
65+ }
66+ }
67+
68+ const fn attr (
69+ label : & ' static str ,
70+ lookup : Option < & ' static str > ,
71+ snippet : Option < & ' static str > ,
72+ ) -> AttrCompletion {
73+ AttrCompletion { label, lookup, snippet, prefer_inner : false }
6074}
6175
6276const ATTRIBUTES : & [ AttrCompletion ] = & [
63- AttrCompletion {
64- label : "allow(…)" ,
65- snippet : Some ( "allow(${0:lint})" ) ,
66- should_be_inner : false ,
67- lookup : Some ( "allow" ) ,
68- } ,
69- AttrCompletion {
70- label : "cfg_attr(…)" ,
71- snippet : Some ( "cfg_attr(${1:predicate}, ${0:attr})" ) ,
72- should_be_inner : false ,
73- lookup : Some ( "cfg_attr" ) ,
74- } ,
75- AttrCompletion {
76- label : "cfg(…)" ,
77- snippet : Some ( "cfg(${0:predicate})" ) ,
78- should_be_inner : false ,
79- lookup : Some ( "cfg" ) ,
80- } ,
81- AttrCompletion {
82- label : "deny(…)" ,
83- snippet : Some ( "deny(${0:lint})" ) ,
84- should_be_inner : false ,
85- lookup : Some ( "deny" ) ,
86- } ,
87- AttrCompletion {
88- label : r#"deprecated = "…""# ,
89- snippet : Some ( r#"deprecated = "${0:reason}""# ) ,
90- should_be_inner : false ,
91- lookup : Some ( "deprecated" ) ,
92- } ,
93- AttrCompletion {
94- label : "derive(…)" ,
95- snippet : Some ( r#"derive(${0:Debug})"# ) ,
96- should_be_inner : false ,
97- lookup : Some ( "derive" ) ,
98- } ,
99- AttrCompletion {
100- label : r#"doc = "…""# ,
101- snippet : Some ( r#"doc = "${0:docs}""# ) ,
102- should_be_inner : false ,
103- lookup : Some ( "doc" ) ,
104- } ,
105- AttrCompletion {
106- label : "feature(…)" ,
107- snippet : Some ( "feature(${0:flag})" ) ,
108- should_be_inner : true ,
109- lookup : Some ( "feature" ) ,
110- } ,
111- AttrCompletion {
112- label : "forbid(…)" ,
113- snippet : Some ( "forbid(${0:lint})" ) ,
114- should_be_inner : false ,
115- lookup : Some ( "forbid" ) ,
116- } ,
77+ attr ( "allow(…)" , Some ( "allow" ) , Some ( "allow(${0:lint})" ) ) ,
78+ attr ( "cfg_attr(…)" , Some ( "cfg_attr" ) , Some ( "cfg_attr(${1:predicate}, ${0:attr})" ) ) ,
79+ attr ( "cfg(…)" , Some ( "cfg" ) , Some ( "cfg(${0:predicate})" ) ) ,
80+ attr ( "deny(…)" , Some ( "deny" ) , Some ( "deny(${0:lint})" ) ) ,
81+ attr ( r#"deprecated = "…""# , Some ( "deprecated" ) , Some ( r#"deprecated = "${0:reason}""# ) ) ,
82+ attr ( "derive(…)" , Some ( "derive" ) , Some ( r#"derive(${0:Debug})"# ) ) ,
83+ attr ( r#"doc = "…""# , Some ( "doc" ) , Some ( r#"doc = "${0:docs}""# ) ) ,
84+ attr ( "feature(…)" , Some ( "feature" ) , Some ( "feature(${0:flag})" ) ) . prefer_inner ( ) ,
85+ attr ( "forbid(…)" , Some ( "forbid" ) , Some ( "forbid(${0:lint})" ) ) ,
11786 // FIXME: resolve through macro resolution?
118- AttrCompletion {
119- label : "global_allocator" ,
120- snippet : None ,
121- should_be_inner : true ,
122- lookup : None ,
123- } ,
124- AttrCompletion {
125- label : "ignore(…)" ,
126- snippet : Some ( "ignore(${0:lint})" ) ,
127- should_be_inner : false ,
128- lookup : Some ( "ignore" ) ,
129- } ,
130- AttrCompletion {
131- label : "inline(…)" ,
132- snippet : Some ( "inline(${0:lint})" ) ,
133- should_be_inner : false ,
134- lookup : Some ( "inline" ) ,
135- } ,
136- AttrCompletion {
137- label : r#"link_name = "…""# ,
138- snippet : Some ( r#"link_name = "${0:symbol_name}""# ) ,
139- should_be_inner : false ,
140- lookup : Some ( "link_name" ) ,
141- } ,
142- AttrCompletion { label : "link" , snippet : None , should_be_inner : false , lookup : None } ,
143- AttrCompletion { label : "macro_export" , snippet : None , should_be_inner : false , lookup : None } ,
144- AttrCompletion { label : "macro_use" , snippet : None , should_be_inner : false , lookup : None } ,
145- AttrCompletion {
146- label : r#"must_use = "…""# ,
147- snippet : Some ( r#"must_use = "${0:reason}""# ) ,
148- should_be_inner : false ,
149- lookup : Some ( "must_use" ) ,
150- } ,
151- AttrCompletion { label : "no_mangle" , snippet : None , should_be_inner : false , lookup : None } ,
152- AttrCompletion { label : "no_std" , snippet : None , should_be_inner : true , lookup : None } ,
153- AttrCompletion { label : "non_exhaustive" , snippet : None , should_be_inner : false , lookup : None } ,
154- AttrCompletion { label : "panic_handler" , snippet : None , should_be_inner : true , lookup : None } ,
155- AttrCompletion {
156- label : "path = \" …\" " ,
157- snippet : Some ( "path =\" ${0:path}\" " ) ,
158- should_be_inner : false ,
159- lookup : Some ( "path" ) ,
160- } ,
161- AttrCompletion { label : "proc_macro" , snippet : None , should_be_inner : false , lookup : None } ,
162- AttrCompletion {
163- label : "proc_macro_attribute" ,
164- snippet : None ,
165- should_be_inner : false ,
166- lookup : None ,
167- } ,
168- AttrCompletion {
169- label : "proc_macro_derive(…)" ,
170- snippet : Some ( "proc_macro_derive(${0:Trait})" ) ,
171- should_be_inner : false ,
172- lookup : Some ( "proc_macro_derive" ) ,
173- } ,
174- AttrCompletion {
175- label : "recursion_limit = …" ,
176- snippet : Some ( "recursion_limit = ${0:128}" ) ,
177- should_be_inner : true ,
178- lookup : Some ( "recursion_limit" ) ,
179- } ,
180- AttrCompletion {
181- label : "repr(…)" ,
182- snippet : Some ( "repr(${0:C})" ) ,
183- should_be_inner : false ,
184- lookup : Some ( "repr" ) ,
185- } ,
186- AttrCompletion {
187- label : "should_panic(…)" ,
188- snippet : Some ( r#"should_panic(expected = "${0:reason}")"# ) ,
189- should_be_inner : false ,
190- lookup : Some ( "should_panic" ) ,
191- } ,
192- AttrCompletion {
193- label : r#"target_feature = "…""# ,
194- snippet : Some ( "target_feature = \" ${0:feature}\" " ) ,
195- should_be_inner : false ,
196- lookup : Some ( "target_feature" ) ,
197- } ,
198- AttrCompletion { label : "test" , snippet : None , should_be_inner : false , lookup : None } ,
199- AttrCompletion { label : "used" , snippet : None , should_be_inner : false , lookup : None } ,
200- AttrCompletion {
201- label : "warn(…)" ,
202- snippet : Some ( "warn(${0:lint})" ) ,
203- should_be_inner : false ,
204- lookup : Some ( "warn" ) ,
205- } ,
206- AttrCompletion {
207- label : r#"windows_subsystem = "…""# ,
208- snippet : Some ( r#"windows_subsystem = "${0:subsystem}""# ) ,
209- should_be_inner : true ,
210- lookup : Some ( "windows_subsystem" ) ,
211- } ,
87+ attr ( "global_allocator" , None , None ) . prefer_inner ( ) ,
88+ attr ( "ignore(…)" , Some ( "ignore" ) , Some ( "ignore(${0:lint})" ) ) ,
89+ attr ( "inline(…)" , Some ( "inline" ) , Some ( "inline(${0:lint})" ) ) ,
90+ attr ( r#"link_name = "…""# , Some ( "link_name" ) , Some ( r#"link_name = "${0:symbol_name}""# ) ) ,
91+ attr ( "link" , None , None ) ,
92+ attr ( "macro_export" , None , None ) ,
93+ attr ( "macro_use" , None , None ) ,
94+ attr ( r#"must_use = "…""# , Some ( "must_use" ) , Some ( r#"must_use = "${0:reason}""# ) ) ,
95+ attr ( "no_mangle" , None , None ) ,
96+ attr ( "no_std" , None , None ) . prefer_inner ( ) ,
97+ attr ( "non_exhaustive" , None , None ) ,
98+ attr ( "panic_handler" , None , None ) . prefer_inner ( ) ,
99+ attr ( "path = \" …\" " , Some ( "path" ) , Some ( "path =\" ${0:path}\" " ) ) ,
100+ attr ( "proc_macro" , None , None ) ,
101+ attr ( "proc_macro_attribute" , None , None ) ,
102+ attr ( "proc_macro_derive(…)" , Some ( "proc_macro_derive" ) , Some ( "proc_macro_derive(${0:Trait})" ) ) ,
103+ attr ( "recursion_limit = …" , Some ( "recursion_limit" ) , Some ( "recursion_limit = ${0:128}" ) )
104+ . prefer_inner ( ) ,
105+ attr ( "repr(…)" , Some ( "repr" ) , Some ( "repr(${0:C})" ) ) ,
106+ attr (
107+ "should_panic(…)" ,
108+ Some ( "should_panic" ) ,
109+ Some ( r#"should_panic(expected = "${0:reason}")"# ) ,
110+ ) ,
111+ attr (
112+ r#"target_feature = "…""# ,
113+ Some ( "target_feature" ) ,
114+ Some ( "target_feature = \" ${0:feature}\" " ) ,
115+ ) ,
116+ attr ( "test" , None , None ) ,
117+ attr ( "used" , None , None ) ,
118+ attr ( "warn(…)" , Some ( "warn" ) , Some ( "warn(${0:lint})" ) ) ,
119+ attr (
120+ r#"windows_subsystem = "…""# ,
121+ Some ( "windows_subsystem" ) ,
122+ Some ( r#"windows_subsystem = "${0:subsystem}""# ) ,
123+ )
124+ . prefer_inner ( ) ,
212125] ;
213126
214127fn complete_derive ( acc : & mut Completions , ctx : & CompletionContext , derive_input : ast:: TokenTree ) {
0 commit comments