mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Rename Atts trait
This commit is contained in:
parent
e42f962766
commit
a87e9145a6
3 changed files with 12 additions and 15 deletions
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static,
|
Adt, Const, Enum, EnumVariant, FieldSource, Function, HasSource, MacroDef, Module, Static,
|
||||||
Struct, StructField, Trait, TypeAlias, Union,
|
Struct, StructField, Trait, TypeAlias, Union,
|
||||||
};
|
};
|
||||||
use hir_def::attr::Attr;
|
use hir_def::attr::{Attr, Attrs};
|
||||||
use hir_expand::hygiene::Hygiene;
|
use hir_expand::hygiene::Hygiene;
|
||||||
use ra_syntax::ast;
|
use ra_syntax::ast;
|
||||||
|
|
||||||
|
@ -36,19 +36,16 @@ impl_froms!(
|
||||||
MacroDef
|
MacroDef
|
||||||
);
|
);
|
||||||
|
|
||||||
pub trait Attrs {
|
pub trait HasAttrs {
|
||||||
fn attrs(&self, db: &impl HirDatabase) -> hir_def::attr::Attrs;
|
fn attrs(&self, db: &impl HirDatabase) -> Attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn attributes_query(
|
pub(crate) fn attributes_query(db: &(impl DefDatabase + AstDatabase), def: AttrDef) -> Attrs {
|
||||||
db: &(impl DefDatabase + AstDatabase),
|
|
||||||
def: AttrDef,
|
|
||||||
) -> hir_def::attr::Attrs {
|
|
||||||
match def {
|
match def {
|
||||||
AttrDef::Module(it) => {
|
AttrDef::Module(it) => {
|
||||||
let src = match it.declaration_source(db) {
|
let src = match it.declaration_source(db) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return hir_def::attr::Attrs::default(),
|
None => return Attrs::default(),
|
||||||
};
|
};
|
||||||
let hygiene = Hygiene::new(db, src.file_id);
|
let hygiene = Hygiene::new(db, src.file_id);
|
||||||
Attr::from_attrs_owner(&src.value, &hygiene)
|
Attr::from_attrs_owner(&src.value, &hygiene)
|
||||||
|
@ -59,7 +56,7 @@ pub(crate) fn attributes_query(
|
||||||
let hygiene = Hygiene::new(db, src.file_id);
|
let hygiene = Hygiene::new(db, src.file_id);
|
||||||
Attr::from_attrs_owner(&named, &hygiene)
|
Attr::from_attrs_owner(&named, &hygiene)
|
||||||
}
|
}
|
||||||
FieldSource::Pos(..) => hir_def::attr::Attrs::default(),
|
FieldSource::Pos(..) => Attrs::default(),
|
||||||
},
|
},
|
||||||
AttrDef::Adt(it) => match it {
|
AttrDef::Adt(it) => match it {
|
||||||
Adt::Struct(it) => attrs_from_ast(it, db),
|
Adt::Struct(it) => attrs_from_ast(it, db),
|
||||||
|
@ -76,7 +73,7 @@ pub(crate) fn attributes_query(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attrs_from_ast<T, D>(node: T, db: &D) -> hir_def::attr::Attrs
|
fn attrs_from_ast<T, D>(node: T, db: &D) -> Attrs
|
||||||
where
|
where
|
||||||
T: HasSource,
|
T: HasSource,
|
||||||
T::Ast: ast::AttrsOwner,
|
T::Ast: ast::AttrsOwner,
|
||||||
|
@ -87,8 +84,8 @@ where
|
||||||
Attr::from_attrs_owner(&src.value, &hygiene)
|
Attr::from_attrs_owner(&src.value, &hygiene)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Into<AttrDef> + Copy> Attrs for T {
|
impl<T: Into<AttrDef> + Copy> HasAttrs for T {
|
||||||
fn attrs(&self, db: &impl HirDatabase) -> hir_def::attr::Attrs {
|
fn attrs(&self, db: &impl HirDatabase) -> Attrs {
|
||||||
db.attrs((*self).into())
|
db.attrs((*self).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ mod marks;
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
code_model::{
|
code_model::{
|
||||||
attrs::{AttrDef, Attrs},
|
attrs::{AttrDef, HasAttrs},
|
||||||
docs::{DocDef, Docs, Documentation},
|
docs::{DocDef, Docs, Documentation},
|
||||||
src::{HasBodySource, HasSource},
|
src::{HasBodySource, HasSource},
|
||||||
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! This modules takes care of rendering various definitions as completion items.
|
//! This modules takes care of rendering various definitions as completion items.
|
||||||
|
|
||||||
use hir::{db::HirDatabase, Attrs, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk};
|
use hir::{db::HirDatabase, Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk};
|
||||||
use join_to_string::join;
|
use join_to_string::join;
|
||||||
use ra_syntax::ast::NameOwner;
|
use ra_syntax::ast::NameOwner;
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
@ -285,7 +285,7 @@ impl Completions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_deprecated(node: impl Attrs, db: &impl HirDatabase) -> bool {
|
fn is_deprecated(node: impl HasAttrs, db: &impl HirDatabase) -> bool {
|
||||||
node.attrs(db).has_atom("deprecated")
|
node.attrs(db).has_atom("deprecated")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue