Skip to content

Commit 544eca1

Browse files
committed
Complete third-party attributes
1 parent 7524850 commit 544eca1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/ide_completion/src/completions/attribute.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module uses a bit of static metadata to provide completions
44
//! for built-in attributes.
55
6+
use hir::HasAttrs;
67
use ide_db::helpers::generated_lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES};
78
use once_cell::sync::Lazy;
89
use rustc_hash::{FxHashMap, FxHashSet};
@@ -81,6 +82,24 @@ fn complete_new_attribute(acc: &mut Completions, ctx: &CompletionContext, attrib
8182
None if is_inner => ATTRIBUTES.iter().for_each(add_completion),
8283
None => ATTRIBUTES.iter().filter(|compl| !compl.prefer_inner).for_each(add_completion),
8384
}
85+
86+
// FIXME: write a test for this when we can
87+
ctx.scope.process_all_names(&mut |name, scope_def| {
88+
if let hir::ScopeDef::MacroDef(mac) = scope_def {
89+
if mac.kind() == hir::MacroKind::Attr {
90+
let mut item = CompletionItem::new(
91+
CompletionKind::Attribute,
92+
ctx.source_range(),
93+
name.to_string(),
94+
);
95+
item.kind(CompletionItemKind::Attribute);
96+
if let Some(docs) = mac.docs(ctx.sema.db) {
97+
item.documentation(docs);
98+
}
99+
acc.add(item.build());
100+
}
101+
}
102+
});
84103
}
85104

86105
struct AttrCompletion {

0 commit comments

Comments
 (0)