Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-completion/src/completions/attribute.rs16
-rw-r--r--crates/ide-completion/src/completions/attribute/cfg.rs7
-rw-r--r--crates/ide-completion/src/completions/attribute/diagnostic.rs70
-rw-r--r--crates/ide-completion/src/completions/attribute/lint.rs18
-rw-r--r--crates/ide-completion/src/completions/attribute/macro_use.rs6
-rw-r--r--crates/ide-completion/src/completions/attribute/repr.rs56
-rw-r--r--crates/ide-completion/src/lib.rs2
7 files changed, 79 insertions, 96 deletions
diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs
index da1e664f96..a518e70861 100644
--- a/crates/ide-completion/src/completions/attribute.rs
+++ b/crates/ide-completion/src/completions/attribute.rs
@@ -37,7 +37,7 @@ pub(crate) use self::derive::complete_derive_path;
pub(crate) fn complete_known_attribute_input(
acc: &mut Completions,
ctx: &CompletionContext<'_>,
- &colon_prefix: &bool,
+ colon_prefix: bool,
fake_attribute_under_caret: &ast::TokenTreeMeta,
extern_crate: Option<&ast::ExternCrate>,
) -> Option<()> {
@@ -49,7 +49,7 @@ pub(crate) fn complete_known_attribute_input(
let tt = attribute.token_tree()?;
match segments.as_slice() {
- ["repr"] => repr::complete_repr(acc, ctx, tt),
+ ["repr"] => repr::complete_repr(acc, ctx, &parse_comma_sep_expr(tt)?),
["feature"] => lint::complete_lint(
acc,
ctx,
@@ -57,12 +57,10 @@ pub(crate) fn complete_known_attribute_input(
&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
- .iter()
- .map(|g| &g.lint)
+ let lints: Vec<Lint> = (CLIPPY_LINT_GROUPS.iter().map(|g| &g.lint))
.chain(DEFAULT_LINTS)
.chain(CLIPPY_LINTS)
.chain(RUSTDOC_LINTS)
@@ -77,7 +75,9 @@ pub(crate) fn complete_known_attribute_input(
extern_crate,
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
),
- ["diagnostic", "on_unimplemented"] => diagnostic::complete_on_unimplemented(acc, ctx, tt),
+ ["diagnostic", "on_unimplemented"] => {
+ diagnostic::complete_on_unimplemented(acc, ctx, &parse_comma_sep_expr(tt)?)
+ }
_ => (),
}
Some(())
@@ -190,7 +190,7 @@ pub(crate) fn complete_attribute_path(
match attributes {
Some(applicable) => applicable
.iter()
- .flat_map(|name| ATTRIBUTES.binary_search_by(|attr| attr.key().cmp(name)).ok())
+ .flat_map(|name| ATTRIBUTES.binary_search_by_key(name, |attr| attr.key()).ok())
.flat_map(|idx| ATTRIBUTES.get(idx))
.for_each(add_completion),
None if is_inner => ATTRIBUTES.iter().for_each(add_completion),
diff --git a/crates/ide-completion/src/completions/attribute/cfg.rs b/crates/ide-completion/src/completions/attribute/cfg.rs
index 0d36fb7a40..1bd6e6d9bf 100644
--- a/crates/ide-completion/src/completions/attribute/cfg.rs
+++ b/crates/ide-completion/src/completions/attribute/cfg.rs
@@ -11,7 +11,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) {
let mut completion =
CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), item, ctx.edition);
completion.insert_text(format!(r#""{item}""#));
- acc.add(completion.build(ctx.db));
+ completion.add_to(acc, ctx.db);
};
// FIXME: Move this into context/analysis.rs
@@ -49,8 +49,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) {
ctx.edition,
);
item.insert_text(insert_text);
-
- acc.add(item.build(ctx.db));
+ item.add_to(acc, ctx.db);
}),
},
None => ctx
@@ -82,7 +81,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) {
{
item.insert_snippet(cap, snippet);
}
- acc.add(item.build(ctx.db));
+ item.add_to(acc, ctx.db);
}),
}
}
diff --git a/crates/ide-completion/src/completions/attribute/diagnostic.rs b/crates/ide-completion/src/completions/attribute/diagnostic.rs
index 8adc974239..0899bbff14 100644
--- a/crates/ide-completion/src/completions/attribute/diagnostic.rs
+++ b/crates/ide-completion/src/completions/attribute/diagnostic.rs
@@ -10,46 +10,44 @@ use super::AttrCompletion;
pub(super) fn complete_on_unimplemented(
acc: &mut Completions,
ctx: &CompletionContext<'_>,
- input: ast::TokenTree,
+ existing_keys: &[ast::Expr],
) {
- if let Some(existing_keys) = super::parse_comma_sep_expr(input) {
- for attr in ATTRIBUTE_ARGS {
- let already_annotated = existing_keys
- .iter()
- .filter_map(|expr| match expr {
- ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
- ast::Expr::BinExpr(bin)
- if bin.op_kind() == Some(ast::BinaryOp::Assignment { op: None }) =>
- {
- match bin.lhs()? {
- ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
- _ => None,
- }
+ for attr in ATTRIBUTE_ARGS {
+ let already_annotated = existing_keys
+ .iter()
+ .filter_map(|expr| match expr {
+ ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
+ ast::Expr::BinExpr(bin)
+ if bin.op_kind() == Some(ast::BinaryOp::Assignment { op: None }) =>
+ {
+ match bin.lhs()? {
+ ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
+ _ => None,
}
- _ => None,
- })
- .any(|it| {
- let text = it.text();
- attr.key() == text && text != "note"
- });
- if already_annotated {
- continue;
- }
+ }
+ _ => None,
+ })
+ .any(|it| {
+ let text = it.text();
+ attr.key() == text && text != "note"
+ });
+ if already_annotated {
+ continue;
+ }
- let mut item = CompletionItem::new(
- SymbolKind::BuiltinAttr,
- ctx.source_range(),
- attr.label,
- ctx.edition,
- );
- if let Some(lookup) = attr.lookup {
- item.lookup_by(lookup);
- }
- if let Some((snippet, cap)) = attr.snippet.zip(ctx.config.snippet_cap) {
- item.insert_snippet(cap, snippet);
- }
- item.add_to(acc, ctx.db);
+ let mut item = CompletionItem::new(
+ SymbolKind::BuiltinAttr,
+ ctx.source_range(),
+ attr.label,
+ ctx.edition,
+ );
+ if let Some(lookup) = attr.lookup {
+ item.lookup_by(lookup);
+ }
+ if let Some((snippet, cap)) = attr.snippet.zip(ctx.config.snippet_cap) {
+ item.insert_snippet(cap, snippet);
}
+ item.add_to(acc, ctx.db);
}
}
diff --git a/crates/ide-completion/src/completions/attribute/lint.rs b/crates/ide-completion/src/completions/attribute/lint.rs
index df577b8ed0..d662f5d543 100644
--- a/crates/ide-completion/src/completions/attribute/lint.rs
+++ b/crates/ide-completion/src/completions/attribute/lint.rs
@@ -12,18 +12,10 @@ pub(super) fn complete_lint(
lints_completions: &[Lint],
) {
for &Lint { label, description, .. } in lints_completions {
- let (qual, name) = {
- // FIXME: change `Lint`'s label to not store a path in it but split the prefix off instead?
- let mut parts = label.split("::");
- let ns_or_label = match parts.next() {
- Some(it) => it,
- None => continue,
- };
- let label = parts.next();
- match label {
- Some(label) => (Some(ns_or_label), label),
- None => (None, ns_or_label),
- }
+ // FIXME: change `Lint`'s label to not store a path in it but split the prefix off instead?
+ let (qual, name) = match label.split_once("::") {
+ Some((qual, name)) => (Some(qual), name),
+ None => (None, label),
};
if qual.is_none() && is_qualified {
// qualified completion requested, but this lint is unqualified
@@ -56,7 +48,7 @@ pub(super) fn complete_lint(
};
let mut item =
CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), label, ctx.edition);
- item.documentation(Documentation::new_owned(description.to_owned()));
+ item.documentation(Documentation::new_borrowed(description));
item.add_to(acc, ctx.db)
}
}
diff --git a/crates/ide-completion/src/completions/attribute/macro_use.rs b/crates/ide-completion/src/completions/attribute/macro_use.rs
index 136315c61f..9c0fe0055d 100644
--- a/crates/ide-completion/src/completions/attribute/macro_use.rs
+++ b/crates/ide-completion/src/completions/attribute/macro_use.rs
@@ -20,11 +20,11 @@ pub(super) fn complete_macro_use(
let mac_name = mac.name(ctx.db);
let mac_name = mac_name.as_str();
- let existing_import = existing_imports
+ let already_imported = existing_imports
.iter()
.filter_map(|p| p.as_single_name_ref())
- .find(|n| n.text() == mac_name);
- if existing_import.is_some() {
+ .any(|n| n.text() == mac_name);
+ if already_imported {
continue;
}
diff --git a/crates/ide-completion/src/completions/attribute/repr.rs b/crates/ide-completion/src/completions/attribute/repr.rs
index cb7ccf7373..b04358963a 100644
--- a/crates/ide-completion/src/completions/attribute/repr.rs
+++ b/crates/ide-completion/src/completions/attribute/repr.rs
@@ -8,42 +8,36 @@ use crate::{Completions, context::CompletionContext, item::CompletionItem};
pub(super) fn complete_repr(
acc: &mut Completions,
ctx: &CompletionContext<'_>,
- input: ast::TokenTree,
+ existing_reprs: &[ast::Expr],
) {
- if let Some(existing_reprs) = super::parse_comma_sep_expr(input) {
- for &ReprCompletion { label, snippet, lookup, collides } in REPR_COMPLETIONS {
- let repr_already_annotated = existing_reprs
- .iter()
- .filter_map(|expr| match expr {
+ for &ReprCompletion { label, snippet, lookup, collides } in REPR_COMPLETIONS {
+ let repr_already_annotated = existing_reprs
+ .iter()
+ .filter_map(|expr| match expr {
+ ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
+ ast::Expr::CallExpr(call) => match call.expr()? {
ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
- ast::Expr::CallExpr(call) => match call.expr()? {
- ast::Expr::PathExpr(path) => path.path()?.as_single_name_ref(),
- _ => None,
- },
_ => None,
- })
- .any(|it| {
- let text = it.text();
- lookup.unwrap_or(label) == text || collides.contains(&text.as_str())
- });
- if repr_already_annotated {
- continue;
- }
+ },
+ _ => None,
+ })
+ .any(|it| {
+ let text = it.text();
+ lookup.unwrap_or(label) == text || collides.contains(&text.as_str())
+ });
+ if repr_already_annotated {
+ continue;
+ }
- let mut item = CompletionItem::new(
- SymbolKind::BuiltinAttr,
- ctx.source_range(),
- label,
- ctx.edition,
- );
- if let Some(lookup) = lookup {
- item.lookup_by(lookup);
- }
- if let Some((snippet, cap)) = snippet.zip(ctx.config.snippet_cap) {
- item.insert_snippet(cap, snippet);
- }
- item.add_to(acc, ctx.db);
+ let mut item =
+ CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), label, ctx.edition);
+ if let Some(lookup) = lookup {
+ item.lookup_by(lookup);
+ }
+ if let Some((snippet, cap)) = snippet.zip(ctx.config.snippet_cap) {
+ item.insert_snippet(cap, snippet);
}
+ item.add_to(acc, ctx.db);
}
}
diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs
index 3df511a5ad..66ecb790a0 100644
--- a/crates/ide-completion/src/lib.rs
+++ b/crates/ide-completion/src/lib.rs
@@ -258,7 +258,7 @@ pub fn completions(
completions::attribute::complete_known_attribute_input(
acc,
ctx,
- colon_prefix,
+ *colon_prefix,
attr,
extern_crate.as_ref(),
);