mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Merge #11040
11040: fix: Don't duplicate attribute completions r=Veykril a=Veykril Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11012 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
f4d65c1d20
4 changed files with 13 additions and 23 deletions
|
@ -216,7 +216,7 @@ impl ItemTree {
|
||||||
self.attrs.get(&of).unwrap_or(&RawAttrs::EMPTY)
|
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)
|
self.raw_attrs(of).clone().filter(db, krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,10 +94,11 @@ pub(crate) fn hover(
|
||||||
let sema = &hir::Semantics::new(db);
|
let sema = &hir::Semantics::new(db);
|
||||||
let file = sema.parse(file_id).syntax().clone();
|
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);
|
return hover_ranged(&file, range, sema, config);
|
||||||
}
|
} else {
|
||||||
let offset = range.start();
|
range.start()
|
||||||
|
};
|
||||||
|
|
||||||
let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
|
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,
|
IDENT | INT_NUMBER | LIFETIME_IDENT | T![self] | T![super] | T![crate] => 3,
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
//!
|
//!
|
||||||
//! This module uses a bit of static metadata to provide completions
|
//! This module uses a bit of static metadata to provide completions
|
||||||
//! for built-in attributes.
|
//! for built-in attributes.
|
||||||
|
//! Non-builtin attribute(excluding derives attributes) completions are done in [`super::unqualified_path`].
|
||||||
|
|
||||||
use hir::HasAttrs;
|
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
helpers::{
|
helpers::{
|
||||||
generated_lints::{CLIPPY_LINTS, DEFAULT_LINTS, FEATURES, RUSTDOC_LINTS},
|
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 if is_inner => ATTRIBUTES.iter().for_each(add_completion),
|
||||||
None => ATTRIBUTES.iter().filter(|compl| !compl.prefer_inner).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 {
|
struct AttrCompletion {
|
||||||
|
|
|
@ -283,7 +283,11 @@ fn attr_on_type_alias() {
|
||||||
#[test]
|
#[test]
|
||||||
fn attr_on_struct() {
|
fn attr_on_struct() {
|
||||||
check(
|
check(
|
||||||
r#"#[$0] struct Foo;"#,
|
r#"
|
||||||
|
//- minicore:derive
|
||||||
|
#[$0]
|
||||||
|
struct Foo;
|
||||||
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
at allow(…)
|
at allow(…)
|
||||||
at cfg(…)
|
at cfg(…)
|
||||||
|
@ -303,6 +307,8 @@ fn attr_on_struct() {
|
||||||
kw self
|
kw self
|
||||||
kw super
|
kw super
|
||||||
kw crate
|
kw crate
|
||||||
|
md core
|
||||||
|
at derive pub macro derive
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue