diff options
Diffstat (limited to 'crates/ide_completion/src/completions/attribute.rs')
-rw-r--r-- | crates/ide_completion/src/completions/attribute.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 3a5bc4381..e846678b4 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs | |||
@@ -39,20 +39,21 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) | |||
39 | } | 39 | } |
40 | 40 | ||
41 | fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) { | 41 | fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) { |
42 | for attr_completion in ATTRIBUTES { | 42 | let is_inner = attribute.kind() == ast::AttrKind::Inner; |
43 | for attr_completion in ATTRIBUTES.iter().filter(|compl| is_inner || !compl.prefer_inner) { | ||
43 | let mut item = CompletionItem::new( | 44 | let mut item = CompletionItem::new( |
44 | CompletionKind::Attribute, | 45 | CompletionKind::Attribute, |
45 | ctx.source_range(), | 46 | ctx.source_range(), |
46 | attr_completion.label, | 47 | attr_completion.label, |
47 | ) | 48 | ); |
48 | .kind(CompletionItemKind::Attribute); | 49 | item.kind(CompletionItemKind::Attribute); |
49 | 50 | ||
50 | if let Some(lookup) = attr_completion.lookup { | 51 | if let Some(lookup) = attr_completion.lookup { |
51 | item = item.lookup_by(lookup); | 52 | item.lookup_by(lookup); |
52 | } | 53 | } |
53 | 54 | ||
54 | if let Some((snippet, cap)) = attr_completion.snippet.zip(ctx.config.snippet_cap) { | 55 | if let Some((snippet, cap)) = attr_completion.snippet.zip(ctx.config.snippet_cap) { |
55 | item = item.insert_snippet(cap, snippet); | 56 | item.insert_snippet(cap, snippet); |
56 | } | 57 | } |
57 | 58 | ||
58 | if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner { | 59 | if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner { |
@@ -167,16 +168,20 @@ fn complete_derive(acc: &mut Completions, ctx: &CompletionContext, derive_input: | |||
167 | ); | 168 | ); |
168 | let lookup = components.join(", "); | 169 | let lookup = components.join(", "); |
169 | let label = components.iter().rev().join(", "); | 170 | let label = components.iter().rev().join(", "); |
170 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label) | 171 | let mut item = |
171 | .lookup_by(lookup) | 172 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label); |
172 | .kind(CompletionItemKind::Attribute) | 173 | item.lookup_by(lookup).kind(CompletionItemKind::Attribute); |
173 | .add_to(acc) | 174 | item.add_to(acc); |
174 | } | 175 | } |
175 | 176 | ||
176 | for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { | 177 | for custom_derive_name in get_derive_names_in_scope(ctx).difference(&existing_derives) { |
177 | CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), custom_derive_name) | 178 | let mut item = CompletionItem::new( |
178 | .kind(CompletionItemKind::Attribute) | 179 | CompletionKind::Attribute, |
179 | .add_to(acc) | 180 | ctx.source_range(), |
181 | custom_derive_name, | ||
182 | ); | ||
183 | item.kind(CompletionItemKind::Attribute); | ||
184 | item.add_to(acc); | ||
180 | } | 185 | } |
181 | } | 186 | } |
182 | } | 187 | } |
@@ -192,14 +197,13 @@ fn complete_lint( | |||
192 | .into_iter() | 197 | .into_iter() |
193 | .filter(|completion| !existing_lints.contains(completion.label)) | 198 | .filter(|completion| !existing_lints.contains(completion.label)) |
194 | { | 199 | { |
195 | CompletionItem::new( | 200 | let mut item = CompletionItem::new( |
196 | CompletionKind::Attribute, | 201 | CompletionKind::Attribute, |
197 | ctx.source_range(), | 202 | ctx.source_range(), |
198 | lint_completion.label, | 203 | lint_completion.label, |
199 | ) | 204 | ); |
200 | .kind(CompletionItemKind::Attribute) | 205 | item.kind(CompletionItemKind::Attribute).detail(lint_completion.description); |
201 | .detail(lint_completion.description) | 206 | item.add_to(acc) |
202 | .add_to(acc) | ||
203 | } | 207 | } |
204 | } | 208 | } |
205 | } | 209 | } |