about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2021-01-07 22:48:54 +0100
committerLukas Wirth <lukastw97@gmail.com>2021-01-07 22:48:54 +0100
commitca6db58762dcd0ee9b7d5fb91c85486c0b90ef4b (patch)
treefe787a45f154951019c9cf49ab80793024b6f3b3
parent5722d2b7b88cf04365037b0769316916e486de48 (diff)
downloadrust-ca6db58762dcd0ee9b7d5fb91c85486c0b90ef4b.tar.gz
rust-ca6db58762dcd0ee9b7d5fb91c85486c0b90ef4b.zip
Tidy up attribute completion match
-rw-r--r--crates/completion/src/completions/attribute.rs30
1 files changed, 11 insertions, 19 deletions
diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs
index 10739750c71..3a29b5203f2 100644
--- a/crates/completion/src/completions/attribute.rs
+++ b/crates/completion/src/completions/attribute.rs
@@ -21,20 +21,15 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
 
     let attribute = ctx.attribute_under_caret.as_ref()?;
     match (attribute.path(), attribute.token_tree()) {
-        (Some(path), Some(token_tree)) if path.to_string() == "derive" => {
-            complete_derive(acc, ctx, token_tree)
-        }
-        (Some(path), Some(token_tree)) if path.to_string() == "feature" => {
-            complete_lint(acc, ctx, token_tree, FEATURES);
-        }
-        (Some(path), Some(token_tree))
-            if ["allow", "warn", "deny", "forbid"]
-                .iter()
-                .any(|lint_level| lint_level == &path.to_string()) =>
-        {
-            complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINT_COMPLETIONS);
-            complete_lint(acc, ctx, token_tree, CLIPPY_LINTS);
-        }
+        (Some(path), Some(token_tree)) => match path.to_string().as_str() {
+            "derive" => complete_derive(acc, ctx, token_tree),
+            "feature" => complete_lint(acc, ctx, token_tree, FEATURES),
+            "allow" | "warn" | "deny" | "forbid" => {
+                complete_lint(acc, ctx, token_tree.clone(), DEFAULT_LINT_COMPLETIONS);
+                complete_lint(acc, ctx, token_tree, CLIPPY_LINTS);
+            }
+            _ => {}
+        },
         (_, Some(_token_tree)) => {}
         _ => complete_attribute_start(acc, ctx, attribute),
     }
@@ -54,11 +49,8 @@ fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attr
             item = item.lookup_by(lookup);
         }
 
-        match (attr_completion.snippet, ctx.config.snippet_cap) {
-            (Some(snippet), Some(cap)) => {
-                item = item.insert_snippet(cap, snippet);
-            }
-            _ => {}
+        if let Some((snippet, cap)) = attr_completion.snippet.zip(ctx.config.snippet_cap) {
+            item = item.insert_snippet(cap, snippet);
         }
 
         if attribute.kind() == ast::AttrKind::Inner || !attr_completion.prefer_inner {