Unnamed repository; edit this file 'description' to name the repository.
simplify `feature.rs` and `lint.rs`
- don't need to pass `lints_completions` -- create in the function - remove qualifier handling from `feature.rs`, as feature names don't have qualifiers
Ada Alakbarova 4 weeks ago
parent 551a85b · commit 7532e95
-rw-r--r--crates/ide-completion/src/completions/attribute.rs26
-rw-r--r--crates/ide-completion/src/completions/attribute/feature.rs52
-rw-r--r--crates/ide-completion/src/completions/attribute/lint.rs14
3 files changed, 30 insertions, 62 deletions
diff --git a/crates/ide-completion/src/completions/attribute.rs b/crates/ide-completion/src/completions/attribute.rs
index 766352aad9..0ce0dde2e2 100644
--- a/crates/ide-completion/src/completions/attribute.rs
+++ b/crates/ide-completion/src/completions/attribute.rs
@@ -4,13 +4,7 @@
use std::sync::LazyLock;
-use ide_db::{
- FxHashMap, SymbolKind,
- generated::lints::{
- CLIPPY_LINT_GROUPS, CLIPPY_LINTS, DEFAULT_LINTS, FEATURES, Lint, RUSTDOC_LINTS,
- },
- syntax_helpers::node_ext::parse_tt_as_comma_sep_paths,
-};
+use ide_db::{FxHashMap, SymbolKind, syntax_helpers::node_ext::parse_tt_as_comma_sep_paths};
use itertools::Itertools;
use syntax::{
AstNode, Edition, SyntaxKind, T,
@@ -51,25 +45,15 @@ pub(crate) fn complete_known_attribute_input(
match segments.as_slice() {
["repr"] => repr::complete_repr(acc, ctx, &parse_comma_sep_expr(tt)?),
- ["feature"] => feature::complete_lint(
+ ["feature"] => {
+ feature::complete_feature(acc, ctx, &parse_tt_as_comma_sep_paths(tt, ctx.edition)?)
+ }
+ ["allow" | "expect" | "deny" | "forbid" | "warn"] => lint::complete_lint(
acc,
ctx,
colon_prefix,
&parse_tt_as_comma_sep_paths(tt, ctx.edition)?,
- FEATURES,
),
- ["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))
- .chain(DEFAULT_LINTS)
- .chain(CLIPPY_LINTS)
- .chain(RUSTDOC_LINTS)
- .cloned()
- .collect();
-
- lint::complete_lint(acc, ctx, colon_prefix, &existing_lints, &lints);
- }
["macro_use"] => macro_use::complete_macro_use(
acc,
ctx,
diff --git a/crates/ide-completion/src/completions/attribute/feature.rs b/crates/ide-completion/src/completions/attribute/feature.rs
index d662f5d543..1e6baca864 100644
--- a/crates/ide-completion/src/completions/attribute/feature.rs
+++ b/crates/ide-completion/src/completions/attribute/feature.rs
@@ -1,51 +1,27 @@
-//! Completion for lints
-use ide_db::{SymbolKind, documentation::Documentation, generated::lints::Lint};
+//! Completion for features
+use ide_db::{
+ SymbolKind,
+ documentation::Documentation,
+ generated::lints::{FEATURES, Lint},
+};
use syntax::ast;
use crate::{Completions, context::CompletionContext, item::CompletionItem};
-pub(super) fn complete_lint(
+pub(super) fn complete_feature(
acc: &mut Completions,
ctx: &CompletionContext<'_>,
- is_qualified: bool,
- existing_lints: &[ast::Path],
- lints_completions: &[Lint],
+ existing_features: &[ast::Path],
) {
- for &Lint { label, description, .. } in lints_completions {
- // 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
- continue;
- }
- let lint_already_annotated = existing_lints
+ for &Lint { label, description, .. } in FEATURES {
+ let feature_already_annotated = existing_features
.iter()
- .filter_map(|path| {
- let q = path.qualifier();
- if q.as_ref().and_then(|it| it.qualifier()).is_some() {
- return None;
- }
- Some((q.and_then(|it| it.as_single_name_ref()), path.segment()?.name_ref()?))
- })
- .any(|(q, name_ref)| {
- let qualifier_matches = match (q, qual) {
- (None, None) => true,
- (None, Some(_)) => false,
- (Some(_), None) => false,
- (Some(q), Some(ns)) => q.text() == ns,
- };
- qualifier_matches && name_ref.text() == name
- });
- if lint_already_annotated {
+ .filter_map(|p| p.as_single_name_ref())
+ .any(|n| n.text() == label);
+ if feature_already_annotated {
continue;
}
- let label = match qual {
- Some(qual) if !is_qualified => format!("{qual}::{name}"),
- _ => name.to_owned(),
- };
+
let mut item =
CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), label, ctx.edition);
item.documentation(Documentation::new_borrowed(description));
diff --git a/crates/ide-completion/src/completions/attribute/lint.rs b/crates/ide-completion/src/completions/attribute/lint.rs
index d662f5d543..f810196bfe 100644
--- a/crates/ide-completion/src/completions/attribute/lint.rs
+++ b/crates/ide-completion/src/completions/attribute/lint.rs
@@ -1,5 +1,9 @@
//! Completion for lints
-use ide_db::{SymbolKind, documentation::Documentation, generated::lints::Lint};
+use ide_db::{
+ SymbolKind,
+ documentation::Documentation,
+ generated::lints::{CLIPPY_LINT_GROUPS, CLIPPY_LINTS, DEFAULT_LINTS, Lint, RUSTDOC_LINTS},
+};
use syntax::ast;
use crate::{Completions, context::CompletionContext, item::CompletionItem};
@@ -9,9 +13,13 @@ pub(super) fn complete_lint(
ctx: &CompletionContext<'_>,
is_qualified: bool,
existing_lints: &[ast::Path],
- lints_completions: &[Lint],
) {
- for &Lint { label, description, .. } in lints_completions {
+ let lints = (CLIPPY_LINT_GROUPS.iter().map(|g| &g.lint))
+ .chain(DEFAULT_LINTS)
+ .chain(CLIPPY_LINTS)
+ .chain(RUSTDOC_LINTS);
+
+ for &Lint { label, description, .. } in lints {
// 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),