Skip to content

Commit 99906ba

Browse files
committed
Fix clippy attribute completions always prefixing with clippy::
1 parent ce47d13 commit 99906ba

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

crates/ide_completion/src/completions/attribute/lint.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Completion for lints
22
use ide_db::helpers::generated_lints::Lint;
3-
use syntax::ast;
3+
use syntax::{ast, T};
44

55
use crate::{
66
context::CompletionContext,
@@ -16,7 +16,7 @@ pub(super) fn complete_lint(
1616
) {
1717
if let Some(existing_lints) = super::parse_comma_sep_paths(derive_input) {
1818
for &Lint { label, description } in lints_completions {
19-
let (ex_q, ex_name) = {
19+
let (qual, name) = {
2020
// FIXME: change `Lint`'s label to not store a path in it but split the prefix off instead?
2121
let mut parts = label.split("::");
2222
let ns_or_label = match parts.next() {
@@ -29,7 +29,7 @@ pub(super) fn complete_lint(
2929
None => (None, ns_or_label),
3030
}
3131
};
32-
let repr_already_annotated = existing_lints
32+
let lint_already_annotated = existing_lints
3333
.iter()
3434
.filter_map(|path| {
3535
let q = path.qualifier();
@@ -38,21 +38,26 @@ pub(super) fn complete_lint(
3838
}
3939
Some((q.and_then(|it| it.as_single_name_ref()), path.segment()?.name_ref()?))
4040
})
41-
.any(|(q, name)| {
42-
let qualifier_matches = match (q, ex_q) {
41+
.any(|(q, name_ref)| {
42+
let qualifier_matches = match (q, qual) {
4343
(None, None) => true,
4444
(None, Some(_)) => false,
4545
(Some(_), None) => false,
4646
(Some(q), Some(ns)) => q.text() == ns,
4747
};
48-
qualifier_matches && name.text() == ex_name
48+
qualifier_matches && name_ref.text() == name
4949
});
50-
if repr_already_annotated {
50+
if lint_already_annotated {
5151
continue;
5252
}
53+
let insert = match qual {
54+
Some(qual) if !ctx.previous_token_is(T![:]) => format!("{}::{}", qual, name),
55+
_ => name.to_owned(),
56+
};
5357
let mut item =
54-
CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), ex_name);
58+
CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label);
5559
item.kind(CompletionItemKind::Attribute)
60+
.insert_text(insert)
5661
.documentation(hir::Documentation::new(description.to_owned()));
5762
item.add_to(acc)
5863
}

crates/ide_completion/src/completions/attribute/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(super) fn complete_repr(acc: &mut Completions, ctx: &CompletionContext, inpu
2323
})
2424
.any(|it| {
2525
let text = it.text();
26-
label == text || collides.contains(&text.as_str())
26+
lookup.unwrap_or(label) == text || collides.contains(&text.as_str())
2727
});
2828
if repr_already_annotated {
2929
continue;

crates/ide_completion/src/tests/attribute.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,24 @@ mod lint {
692692
r#"#[feature(box_syntax)] struct Test;"#,
693693
)
694694
}
695+
696+
#[test]
697+
fn lint_clippy_unqualified() {
698+
check_edit(
699+
"clippy::as_conversions",
700+
r#"#[allow($0)] struct Test;"#,
701+
r#"#[allow(clippy::as_conversions)] struct Test;"#,
702+
);
703+
}
704+
705+
#[test]
706+
fn lint_clippy_qualified() {
707+
check_edit(
708+
"clippy::as_conversions",
709+
r#"#[allow(clippy::$0)] struct Test;"#,
710+
r#"#[allow(clippy::as_conversions)] struct Test;"#,
711+
);
712+
}
695713
}
696714

697715
mod repr {
@@ -742,7 +760,6 @@ mod repr {
742760
check_repr(
743761
r#"#[repr(align(1), $0)] struct Test;"#,
744762
expect![[r#"
745-
at align($0)
746763
at transparent
747764
at C
748765
at u8

crates/rust-analyzer/tests/slow-tests/tidy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ fn deny_clippy(path: &Path, text: &str) {
192192
"ide_db/src/helpers/generated_lints.rs",
193193
// The tests test clippy lint hovers
194194
"ide/src/hover/tests.rs",
195+
// The tests test clippy lint completions
196+
"ide_completion/src/tests/attribute.rs",
195197
];
196198
if ignore.iter().any(|p| path.ends_with(p)) {
197199
return;

0 commit comments

Comments
 (0)