Skip to content

Commit d3e5386

Browse files
committed
fix: Don't duplicate attribute completions
1 parent f79f3db commit d3e5386

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

crates/hir_def/src/item_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl ItemTree {
216216
self.attrs.get(&of).unwrap_or(&RawAttrs::EMPTY)
217217
}
218218

219-
pub fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
219+
pub(crate) fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
220220
self.raw_attrs(of).clone().filter(db, krate)
221221
}
222222

crates/ide/src/hover.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ pub(crate) fn hover(
9494
let sema = &hir::Semantics::new(db);
9595
let file = sema.parse(file_id).syntax().clone();
9696

97-
if !range.is_empty() {
97+
let offset = if !range.is_empty() {
9898
return hover_ranged(&file, range, sema, config);
99-
}
100-
let offset = range.start();
99+
} else {
100+
range.start()
101+
};
101102

102103
let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
103104
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,

crates/ide_completion/src/completions/attribute.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//!
33
//! This module uses a bit of static metadata to provide completions
44
//! for built-in attributes.
5+
//! Non-builtin attribute(excluding derives attributes) completions are done in [`super::unqualified_path`].
56
6-
use hir::HasAttrs;
77
use ide_db::{
88
helpers::{
99
generated_lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES, RUSTDOC_LINTS},
@@ -93,23 +93,6 @@ fn complete_new_attribute(acc: &mut Completions, ctx: &CompletionContext, attrib
9393
None if is_inner => ATTRIBUTES.iter().for_each(add_completion),
9494
None => ATTRIBUTES.iter().filter(|compl| !compl.prefer_inner).for_each(add_completion),
9595
}
96-
97-
// FIXME: write a test for this when we can
98-
ctx.scope.process_all_names(&mut |name, scope_def| {
99-
if let hir::ScopeDef::MacroDef(mac) = scope_def {
100-
if mac.kind() == hir::MacroKind::Attr {
101-
let mut item = CompletionItem::new(
102-
SymbolKind::Attribute,
103-
ctx.source_range(),
104-
name.to_smol_str(),
105-
);
106-
if let Some(docs) = mac.docs(ctx.sema.db) {
107-
item.documentation(docs);
108-
}
109-
item.add_to(acc);
110-
}
111-
}
112-
});
11396
}
11497

11598
struct AttrCompletion {

crates/ide_completion/src/tests/attribute.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ fn attr_on_type_alias() {
283283
#[test]
284284
fn attr_on_struct() {
285285
check(
286-
r#"#[$0] struct Foo;"#,
286+
r#"
287+
//- minicore:derive
288+
#[$0]
289+
struct Foo;
290+
"#,
287291
expect![[r#"
288292
at allow(…)
289293
at cfg(…)
@@ -303,6 +307,8 @@ fn attr_on_struct() {
303307
kw self
304308
kw super
305309
kw crate
310+
md core
311+
at derive pub macro derive
306312
"#]],
307313
);
308314
}

0 commit comments

Comments
 (0)