diff options
author | Aleksey Kladov <[email protected]> | 2020-07-03 14:38:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-03 14:38:53 +0100 |
commit | f1671f460ba3a44baa49ca7413646f84f86be842 (patch) | |
tree | a5828618f9cb1e9ad3f15adb4f5d0dfd57e08d55 | |
parent | ef6a6d75d5dba2825e6b90e67e0b147a5f7158e1 (diff) |
Compress attribute completion tests
-rw-r--r-- | crates/ra_ide/src/completion/complete_attribute.rs | 213 |
1 files changed, 63 insertions, 150 deletions
diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index 6beeca457..4e50a294f 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs | |||
@@ -46,7 +46,7 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr | |||
46 | _ => {} | 46 | _ => {} |
47 | } | 47 | } |
48 | 48 | ||
49 | if attribute.kind() == ast::AttrKind::Inner || !attr_completion.should_be_inner { | 49 | if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner { |
50 | acc.add(item); | 50 | acc.add(item); |
51 | } | 51 | } |
52 | } | 52 | } |
@@ -56,159 +56,72 @@ struct AttrCompletion { | |||
56 | label: &'static str, | 56 | label: &'static str, |
57 | lookup: Option<&'static str>, | 57 | lookup: Option<&'static str>, |
58 | snippet: Option<&'static str>, | 58 | 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 } | ||
60 | } | 74 | } |
61 | 75 | ||
62 | const ATTRIBUTES: &[AttrCompletion] = &[ | 76 | const ATTRIBUTES: &[AttrCompletion] = &[ |
63 | AttrCompletion { | 77 | attr("allow(…)", Some("allow"), Some("allow(${0:lint})")), |
64 | label: "allow(…)", | 78 | attr("cfg_attr(…)", Some("cfg_attr"), Some("cfg_attr(${1:predicate}, ${0:attr})")), |
65 | snippet: Some("allow(${0:lint})"), | 79 | attr("cfg(…)", Some("cfg"), Some("cfg(${0:predicate})")), |
66 | should_be_inner: false, | 80 | attr("deny(…)", Some("deny"), Some("deny(${0:lint})")), |
67 | lookup: Some("allow"), | 81 | attr(r#"deprecated = "…""#, Some("deprecated"), Some(r#"deprecated = "${0:reason}""#)), |
68 | }, | 82 | attr("derive(…)", Some("derive"), Some(r#"derive(${0:Debug})"#)), |
69 | AttrCompletion { | 83 | attr(r#"doc = "…""#, Some("doc"), Some(r#"doc = "${0:docs}""#)), |
70 | label: "cfg_attr(…)", | 84 | attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), |
71 | snippet: Some("cfg_attr(${1:predicate}, ${0:attr})"), | 85 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), |
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 | }, | ||
117 | // FIXME: resolve through macro resolution? | 86 | // FIXME: resolve through macro resolution? |
118 | AttrCompletion { | 87 | attr("global_allocator", None, None).prefer_inner(), |
119 | label: "global_allocator", | 88 | attr("ignore(…)", Some("ignore"), Some("ignore(${0:lint})")), |
120 | snippet: None, | 89 | attr("inline(…)", Some("inline"), Some("inline(${0:lint})")), |
121 | should_be_inner: true, | 90 | attr(r#"link_name = "…""#, Some("link_name"), Some(r#"link_name = "${0:symbol_name}""#)), |
122 | lookup: None, | 91 | attr("link", None, None), |
123 | }, | 92 | attr("macro_export", None, None), |
124 | AttrCompletion { | 93 | attr("macro_use", None, None), |
125 | label: "ignore(…)", | 94 | attr(r#"must_use = "…""#, Some("must_use"), Some(r#"must_use = "${0:reason}""#)), |
126 | snippet: Some("ignore(${0:lint})"), | 95 | attr("no_mangle", None, None), |
127 | should_be_inner: false, | 96 | attr("no_std", None, None).prefer_inner(), |
128 | lookup: Some("ignore"), | 97 | attr("non_exhaustive", None, None), |
129 | }, | 98 | attr("panic_handler", None, None).prefer_inner(), |
130 | AttrCompletion { | 99 | attr("path = \"…\"", Some("path"), Some("path =\"${0:path}\"")), |
131 | label: "inline(…)", | 100 | attr("proc_macro", None, None), |
132 | snippet: Some("inline(${0:lint})"), | 101 | attr("proc_macro_attribute", None, None), |
133 | should_be_inner: false, | 102 | attr("proc_macro_derive(…)", Some("proc_macro_derive"), Some("proc_macro_derive(${0:Trait})")), |
134 | lookup: Some("inline"), | 103 | attr("recursion_limit = …", Some("recursion_limit"), Some("recursion_limit = ${0:128}")) |
135 | }, | 104 | .prefer_inner(), |
136 | AttrCompletion { | 105 | attr("repr(…)", Some("repr"), Some("repr(${0:C})")), |
137 | label: r#"link_name = "…""#, | 106 | attr( |
138 | snippet: Some(r#"link_name = "${0:symbol_name}""#), | 107 | "should_panic(…)", |
139 | should_be_inner: false, | 108 | Some("should_panic"), |
140 | lookup: Some("link_name"), | 109 | Some(r#"should_panic(expected = "${0:reason}")"#), |
141 | }, | 110 | ), |
142 | AttrCompletion { label: "link", snippet: None, should_be_inner: false, lookup: None }, | 111 | attr( |
143 | AttrCompletion { label: "macro_export", snippet: None, should_be_inner: false, lookup: None }, | 112 | r#"target_feature = "…""#, |
144 | AttrCompletion { label: "macro_use", snippet: None, should_be_inner: false, lookup: None }, | 113 | Some("target_feature"), |
145 | AttrCompletion { | 114 | Some("target_feature = \"${0:feature}\""), |
146 | label: r#"must_use = "…""#, | 115 | ), |
147 | snippet: Some(r#"must_use = "${0:reason}""#), | 116 | attr("test", None, None), |
148 | should_be_inner: false, | 117 | attr("used", None, None), |
149 | lookup: Some("must_use"), | 118 | attr("warn(…)", Some("warn"), Some("warn(${0:lint})")), |
150 | }, | 119 | attr( |
151 | AttrCompletion { label: "no_mangle", snippet: None, should_be_inner: false, lookup: None }, | 120 | r#"windows_subsystem = "…""#, |
152 | AttrCompletion { label: "no_std", snippet: None, should_be_inner: true, lookup: None }, | 121 | Some("windows_subsystem"), |
153 | AttrCompletion { label: "non_exhaustive", snippet: None, should_be_inner: false, lookup: None }, | 122 | Some(r#"windows_subsystem = "${0:subsystem}""#), |
154 | AttrCompletion { label: "panic_handler", snippet: None, should_be_inner: true, lookup: None }, | 123 | ) |
155 | AttrCompletion { | 124 | .prefer_inner(), |
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 | }, | ||
212 | ]; | 125 | ]; |
213 | 126 | ||
214 | fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { | 127 | fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: ast::TokenTree) { |