Unnamed repository; edit this file 'description' to name the repository.
match on segments of path and some small cleanup
Ryan Mehri 11 months ago
parent 7e8079f · commit f1cc7c5
-rw-r--r--crates/ide-completion/src/completions/attribute.rs31
-rw-r--r--crates/ide-completion/src/completions/attribute/diagnostic.rs6
2 files changed, 14 insertions, 23 deletions
diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs
index f696f0c0b9..0ca90fae4e 100644
--- a/crates/ide-completion/src/completions/attribute.rs
+++ b/crates/ide-completion/src/completions/attribute.rs
@@ -42,31 +42,21 @@ pub(crate) fn complete_known_attribute_input(
) -> Option<()> {
let attribute = fake_attribute_under_caret;
let path = attribute.path()?;
- let name_ref = path.segment()?.name_ref();
- let (name_ref, tt) = name_ref.zip(attribute.token_tree())?;
- tt.l_paren_token()?;
+ let segments = path.segments().map(|s| s.name_ref()).collect::<Option<Vec<_>>>()?;
+ let segments = segments.iter().map(|n| n.text()).collect::<Vec<_>>();
+ let segments = segments.iter().map(|t| t.as_str()).collect::<Vec<_>>();
+ let tt = attribute.token_tree()?;
- if let Some(qualifier) = path.qualifier() {
- let qualifier_name_ref = qualifier.as_single_name_ref()?;
- match (qualifier_name_ref.text().as_str(), name_ref.text().as_str()) {
- ("diagnostic", "on_unimplemented") => {
- diagnostic::complete_on_unimplemented(acc, ctx, tt)
- }
- _ => (),
- }
- return Some(());
- }
-
- match name_ref.text().as_str() {
- "repr" => repr::complete_repr(acc, ctx, tt),
- "feature" => lint::complete_lint(
+ match segments.as_slice() {
+ ["repr"] => repr::complete_repr(acc, ctx, tt),
+ ["feature"] => lint::complete_lint(
acc,
ctx,
colon_prefix,
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
FEATURES,
),
- "allow" | "expect" | "deny" | "forbid" | "warn" => {
+ ["allow"] | ["expect"] | ["deny"] | ["forbid"] | ["warn"] => {
let existing_lints = parse_tt_as_comma_sep_paths(tt, ctx.edition)?;
let lints: Vec<Lint> = CLIPPY_LINT_GROUPS
@@ -80,13 +70,14 @@ pub(crate) fn complete_known_attribute_input(
lint::complete_lint(acc, ctx, colon_prefix, &existing_lints, &lints);
}
- "cfg" => cfg::complete_cfg(acc, ctx),
- "macro_use" => macro_use::complete_macro_use(
+ ["cfg"] => cfg::complete_cfg(acc, ctx),
+ ["macro_use"] => macro_use::complete_macro_use(
acc,
ctx,
extern_crate,
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
),
+ ["diagnostic", "on_unimplemented"] => diagnostic::complete_on_unimplemented(acc, ctx, tt),
_ => (),
}
Some(())
diff --git a/crates/ide-completion/src/completions/attribute/diagnostic.rs b/crates/ide-completion/src/completions/attribute/diagnostic.rs
index 10c5135b4b..8adc974239 100644
--- a/crates/ide-completion/src/completions/attribute/diagnostic.rs
+++ b/crates/ide-completion/src/completions/attribute/diagnostic.rs
@@ -1,7 +1,7 @@
//! Completion for diagnostic attributes.
use ide_db::SymbolKind;
-use syntax::ast::{self};
+use syntax::ast;
use crate::{CompletionItem, Completions, context::CompletionContext};
@@ -13,7 +13,7 @@ pub(super) fn complete_on_unimplemented(
input: ast::TokenTree,
) {
if let Some(existing_keys) = super::parse_comma_sep_expr(input) {
- for attr in ATTRIBUTES {
+ for attr in ATTRIBUTE_ARGS {
let already_annotated = existing_keys
.iter()
.filter_map(|expr| match expr {
@@ -53,7 +53,7 @@ pub(super) fn complete_on_unimplemented(
}
}
-const ATTRIBUTES: &[AttrCompletion] = &[
+const ATTRIBUTE_ARGS: &[AttrCompletion] = &[
super::attr(r#"label = "…""#, Some("label"), Some(r#"label = "${0:label}""#)),
super::attr(r#"message = "…""#, Some("message"), Some(r#"message = "${0:message}""#)),
super::attr(r#"note = "…""#, Some("note"), Some(r#"note = "${0:note}""#)),