From 845904f0bb9745b08d987d66f445d07eac4da789 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 14 Sep 2021 00:31:14 +0200 Subject: [PATCH] fix: do not complete builtin attributes for qualified paths --- crates/ide_completion/src/completions/attribute.rs | 6 +++++- crates/ide_completion/src/tests/attribute.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 8acb26ffa16..2b130cecf5c 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs @@ -22,7 +22,11 @@ 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 72c47fe96e9..7d0bdc58210 100644 --- a/crates/ide_completion/src/tests/attribute.rs +++ b/crates/ide_completion/src/tests/attribute.rs @@ -33,6 +33,18 @@ fn doesnt_complete_items() { ) } +#[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![[]])