]> git.lizzy.rs Git - rust.git/commitdiff
fix: Don't duplicate attribute completions
authorLukas Wirth <lukastw97@gmail.com>
Fri, 17 Dec 2021 14:22:53 +0000 (15:22 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Fri, 17 Dec 2021 14:22:53 +0000 (15:22 +0100)
crates/hir_def/src/item_tree.rs
crates/ide/src/hover.rs
crates/ide_completion/src/completions/attribute.rs
crates/ide_completion/src/tests/attribute.rs

index 68d77084a3cbda3423769bb20526f3715997511b..5e260880ffde71faffd4503eca21a7c65be6ede1 100644 (file)
@@ -216,7 +216,7 @@ pub(crate) fn raw_attrs(&self, of: AttrOwner) -> &RawAttrs {
         self.attrs.get(&of).unwrap_or(&RawAttrs::EMPTY)
     }
 
-    pub fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
+    pub(crate) fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
         self.raw_attrs(of).clone().filter(db, krate)
     }
 
index 7d5cfaa93728a24e90d6a834e6e7204ea0a4fdcc..9d19d7c1c015e35fb4c6a14fd2733a0ced74c1c6 100644 (file)
@@ -94,10 +94,11 @@ pub(crate) fn hover(
     let sema = &hir::Semantics::new(db);
     let file = sema.parse(file_id).syntax().clone();
 
-    if !range.is_empty() {
+    let offset = if !range.is_empty() {
         return hover_ranged(&file, range, sema, config);
-    }
-    let offset = range.start();
+    } else {
+        range.start()
+    };
 
     let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
         IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
index d92e311915a1e1b3220455069072170a19c2a716..d642c8bc4df18bc0d4d18cd91713ebf7ed4246ee 100644 (file)
@@ -2,8 +2,8 @@
 //!
 //! This module uses a bit of static metadata to provide completions
 //! for built-in attributes.
+//! Non-builtin attribute(excluding derives attributes) completions are done in [`super::unqualified_path`].
 
-use hir::HasAttrs;
 use ide_db::{
     helpers::{
         generated_lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES, RUSTDOC_LINTS},
@@ -93,23 +93,6 @@ fn complete_new_attribute(acc: &mut Completions, ctx: &CompletionContext, attrib
         None if is_inner => ATTRIBUTES.iter().for_each(add_completion),
         None => ATTRIBUTES.iter().filter(|compl| !compl.prefer_inner).for_each(add_completion),
     }
-
-    // FIXME: write a test for this when we can
-    ctx.scope.process_all_names(&mut |name, scope_def| {
-        if let hir::ScopeDef::MacroDef(mac) = scope_def {
-            if mac.kind() == hir::MacroKind::Attr {
-                let mut item = CompletionItem::new(
-                    SymbolKind::Attribute,
-                    ctx.source_range(),
-                    name.to_smol_str(),
-                );
-                if let Some(docs) = mac.docs(ctx.sema.db) {
-                    item.documentation(docs);
-                }
-                item.add_to(acc);
-            }
-        }
-    });
 }
 
 struct AttrCompletion {
index c90d4966f37a6d65ab37b00082c7778db6001a70..c2bd26e2d8ede2a1290d6c7881dcdc7258ca7399 100644 (file)
@@ -283,7 +283,11 @@ fn attr_on_type_alias() {
 #[test]
 fn attr_on_struct() {
     check(
-        r#"#[$0] struct Foo;"#,
+        r#"
+//- minicore:derive
+#[$0]
+struct Foo;
+"#,
         expect![[r#"
             at allow(…)
             at cfg(…)
@@ -303,6 +307,8 @@ fn attr_on_struct() {
             kw self
             kw super
             kw crate
+            md core
+            at derive           pub macro derive
         "#]],
     );
 }