Unnamed repository; edit this file 'description' to name the repository.
Merge #10229
10229: fix: do not complete builtin attributes for qualified paths r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
bors[bot] 2021-09-14
parent 6eecd84 · parent 845904f · commit 249ebdd
-rw-r--r--crates/ide_completion/src/completions/attribute.rs6
-rw-r--r--crates/ide_completion/src/tests/attribute.rs12
2 files changed, 17 insertions, 1 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs
index 8acb26ffa1..2b130cecf5 100644
--- a/crates/ide_completion/src/completions/attribute.rs
+++ b/crates/ide_completion/src/completions/attribute.rs
@@ -22,7 +22,11 @@ mod repr;
pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
let attribute = ctx.attribute_under_caret.as_ref()?;
- match (attribute.path().and_then(|p| p.as_single_name_ref()), attribute.token_tree()) {
+ let name_ref = match attribute.path() {
+ Some(p) => Some(p.as_single_name_ref()?),
+ None => None,
+ };
+ match (name_ref, attribute.token_tree()) {
(Some(path), Some(token_tree)) => match path.text().as_str() {
"derive" => derive::complete_derive(acc, ctx, token_tree),
"repr" => repr::complete_repr(acc, ctx, token_tree),
diff --git a/crates/ide_completion/src/tests/attribute.rs b/crates/ide_completion/src/tests/attribute.rs
index 72c47fe96e..7d0bdc5821 100644
--- a/crates/ide_completion/src/tests/attribute.rs
+++ b/crates/ide_completion/src/tests/attribute.rs
@@ -34,6 +34,18 @@ use self as this;
}
#[test]
+fn doesnt_complete_qualified() {
+ check(
+ r#"
+struct Foo;
+#[foo::$0]
+use self as this;
+"#,
+ expect![[r#""#]],
+ )
+}
+
+#[test]
fn inside_nested_attr() {
check(r#"#[cfg($0)]"#, expect![[]])
}