aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-06-18 20:31:49 +0100
committerBenjamin Coenen <[email protected]>2020-06-18 20:31:49 +0100
commit3f26c5758d7beb1207ed187b71fe9fa6fcaa03ec (patch)
treefc47f0b81a6bc44346b91485cb0dce70a82e5d8a
parent9aad07dbea39132692ff68bd421b88aad9644d81 (diff)
don't complete top level attrs inside nested attrs and add better labels #4890
Signed-off-by: Benjamin Coenen <[email protected]>
-rw-r--r--crates/ra_ide/src/completion/complete_attribute.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs
index 814d7109d..9c7ccc950 100644
--- a/crates/ra_ide/src/completion/complete_attribute.rs
+++ b/crates/ra_ide/src/completion/complete_attribute.rs
@@ -22,24 +22,18 @@ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
22 } 22 }
23 (_, Some(ast::AttrInput::TokenTree(token_tree))) => { 23 (_, Some(ast::AttrInput::TokenTree(token_tree))) => {
24 let token_tree_str = token_tree.to_string(); 24 let token_tree_str = token_tree.to_string();
25 complete_attribute_start( 25 let nested = token_tree_str.starts_with('(') && token_tree_str.ends_with(')');
26 acc, 26
27 ctx, 27 if !nested {
28 attribute, 28 complete_attribute_start(acc, ctx, attribute);
29 token_tree_str.starts_with('(') && token_tree_str.ends_with(')'), 29 }
30 )
31 } 30 }
32 _ => complete_attribute_start(acc, ctx, attribute, false), 31 _ => complete_attribute_start(acc, ctx, attribute),
33 } 32 }
34 Some(()) 33 Some(())
35} 34}
36 35
37fn complete_attribute_start( 36fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) {
38 acc: &mut Completions,
39 ctx: &CompletionContext,
40 attribute: &ast::Attr,
41 nested: bool,
42) {
43 for attr_completion in ATTRIBUTES { 37 for attr_completion in ATTRIBUTES {
44 let mut item = CompletionItem::new( 38 let mut item = CompletionItem::new(
45 CompletionKind::Attribute, 39 CompletionKind::Attribute,
@@ -56,9 +50,7 @@ fn complete_attribute_start(
56 } 50 }
57 51
58 if attribute.kind() == ast::AttrKind::Inner || !attr_completion.should_be_inner { 52 if attribute.kind() == ast::AttrKind::Inner || !attr_completion.should_be_inner {
59 if (nested && attr_completion.should_be_inner) || !nested { 53 acc.add(item);
60 acc.add(item);
61 }
62 } 54 }
63 } 55 }
64} 56}