Fix clippy attribute completions always prefixing with clippy::
This commit is contained in:
parent
ce47d13101
commit
99906baa17
@ -1,6 +1,6 @@
|
|||||||
//! Completion for lints
|
//! Completion for lints
|
||||||
use ide_db::helpers::generated_lints::Lint;
|
use ide_db::helpers::generated_lints::Lint;
|
||||||
use syntax::ast;
|
use syntax::{ast, T};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::CompletionContext,
|
context::CompletionContext,
|
||||||
@ -16,7 +16,7 @@ pub(super) fn complete_lint(
|
|||||||
) {
|
) {
|
||||||
if let Some(existing_lints) = super::parse_comma_sep_paths(derive_input) {
|
if let Some(existing_lints) = super::parse_comma_sep_paths(derive_input) {
|
||||||
for &Lint { label, description } in lints_completions {
|
for &Lint { label, description } in lints_completions {
|
||||||
let (ex_q, ex_name) = {
|
let (qual, name) = {
|
||||||
// FIXME: change `Lint`'s label to not store a path in it but split the prefix off instead?
|
// FIXME: change `Lint`'s label to not store a path in it but split the prefix off instead?
|
||||||
let mut parts = label.split("::");
|
let mut parts = label.split("::");
|
||||||
let ns_or_label = match parts.next() {
|
let ns_or_label = match parts.next() {
|
||||||
@ -29,7 +29,7 @@ pub(super) fn complete_lint(
|
|||||||
None => (None, ns_or_label),
|
None => (None, ns_or_label),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let repr_already_annotated = existing_lints
|
let lint_already_annotated = existing_lints
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|path| {
|
.filter_map(|path| {
|
||||||
let q = path.qualifier();
|
let q = path.qualifier();
|
||||||
@ -38,21 +38,26 @@ pub(super) fn complete_lint(
|
|||||||
}
|
}
|
||||||
Some((q.and_then(|it| it.as_single_name_ref()), path.segment()?.name_ref()?))
|
Some((q.and_then(|it| it.as_single_name_ref()), path.segment()?.name_ref()?))
|
||||||
})
|
})
|
||||||
.any(|(q, name)| {
|
.any(|(q, name_ref)| {
|
||||||
let qualifier_matches = match (q, ex_q) {
|
let qualifier_matches = match (q, qual) {
|
||||||
(None, None) => true,
|
(None, None) => true,
|
||||||
(None, Some(_)) => false,
|
(None, Some(_)) => false,
|
||||||
(Some(_), None) => false,
|
(Some(_), None) => false,
|
||||||
(Some(q), Some(ns)) => q.text() == ns,
|
(Some(q), Some(ns)) => q.text() == ns,
|
||||||
};
|
};
|
||||||
qualifier_matches && name.text() == ex_name
|
qualifier_matches && name_ref.text() == name
|
||||||
});
|
});
|
||||||
if repr_already_annotated {
|
if lint_already_annotated {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let insert = match qual {
|
||||||
|
Some(qual) if !ctx.previous_token_is(T![:]) => format!("{}::{}", qual, name),
|
||||||
|
_ => name.to_owned(),
|
||||||
|
};
|
||||||
let mut item =
|
let mut item =
|
||||||
CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), ex_name);
|
CompletionItem::new(CompletionKind::Attribute, ctx.source_range(), label);
|
||||||
item.kind(CompletionItemKind::Attribute)
|
item.kind(CompletionItemKind::Attribute)
|
||||||
|
.insert_text(insert)
|
||||||
.documentation(hir::Documentation::new(description.to_owned()));
|
.documentation(hir::Documentation::new(description.to_owned()));
|
||||||
item.add_to(acc)
|
item.add_to(acc)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ pub(super) fn complete_repr(acc: &mut Completions, ctx: &CompletionContext, inpu
|
|||||||
})
|
})
|
||||||
.any(|it| {
|
.any(|it| {
|
||||||
let text = it.text();
|
let text = it.text();
|
||||||
label == text || collides.contains(&text.as_str())
|
lookup.unwrap_or(label) == text || collides.contains(&text.as_str())
|
||||||
});
|
});
|
||||||
if repr_already_annotated {
|
if repr_already_annotated {
|
||||||
continue;
|
continue;
|
||||||
|
@ -692,6 +692,24 @@ mod lint {
|
|||||||
r#"#[feature(box_syntax)] struct Test;"#,
|
r#"#[feature(box_syntax)] struct Test;"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lint_clippy_unqualified() {
|
||||||
|
check_edit(
|
||||||
|
"clippy::as_conversions",
|
||||||
|
r#"#[allow($0)] struct Test;"#,
|
||||||
|
r#"#[allow(clippy::as_conversions)] struct Test;"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lint_clippy_qualified() {
|
||||||
|
check_edit(
|
||||||
|
"clippy::as_conversions",
|
||||||
|
r#"#[allow(clippy::$0)] struct Test;"#,
|
||||||
|
r#"#[allow(clippy::as_conversions)] struct Test;"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod repr {
|
mod repr {
|
||||||
@ -742,7 +760,6 @@ mod repr {
|
|||||||
check_repr(
|
check_repr(
|
||||||
r#"#[repr(align(1), $0)] struct Test;"#,
|
r#"#[repr(align(1), $0)] struct Test;"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
at align($0)
|
|
||||||
at transparent
|
at transparent
|
||||||
at C
|
at C
|
||||||
at u8
|
at u8
|
||||||
|
@ -192,6 +192,8 @@ fn deny_clippy(path: &Path, text: &str) {
|
|||||||
"ide_db/src/helpers/generated_lints.rs",
|
"ide_db/src/helpers/generated_lints.rs",
|
||||||
// The tests test clippy lint hovers
|
// The tests test clippy lint hovers
|
||||||
"ide/src/hover/tests.rs",
|
"ide/src/hover/tests.rs",
|
||||||
|
// The tests test clippy lint completions
|
||||||
|
"ide_completion/src/tests/attribute.rs",
|
||||||
];
|
];
|
||||||
if ignore.iter().any(|p| path.ends_with(p)) {
|
if ignore.iter().any(|p| path.ends_with(p)) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user