From 1a9986496387544c048475765ac64e83518437af Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 12:01:56 +0300 Subject: Use attrs rather than syntax for lang items --- crates/ra_hir_def/src/attr.rs | 24 +++++++++++++++++------- crates/ra_hir_def/src/lib.rs | 4 +++- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index ce397f6b0..eee5e44bf 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -53,28 +53,38 @@ impl Attrs { } } } - AttrDefId::AdtId(it) => match it { - AdtId::StructId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), - AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), - AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), - }, AttrDefId::EnumVariantId(it) => { let src = it.parent.child_source(db); let hygiene = Hygiene::new(db, src.file_id); Attr::from_attrs_owner(&src.value[it.local_id], &hygiene) } + AttrDefId::AdtId(it) => match it { + AdtId::StructId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), + AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), + AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), + }, AttrDefId::StaticId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), + AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), + AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db), + AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), - AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db), - AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db), } } pub fn has_atom(&self, atom: &str) -> bool { self.iter().any(|it| it.is_simple_atom(atom)) } + + pub fn find_string_value(&self, key: &str) -> Option { + self.iter().filter(|attr| attr.is_simple_atom(key)).find_map(|attr| { + match attr.input.as_ref()? { + AttrInput::Literal(it) => Some(it.clone()), + _ => None, + } + }) + } } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 1bcdf9b78..20d4deadb 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -489,6 +489,7 @@ pub enum AttrDefId { TraitId(TraitId), TypeAliasId(TypeAliasId), MacroDefId(MacroDefId), + ImplId(ImplId), } impl_froms!( @@ -501,7 +502,8 @@ impl_froms!( FunctionId, TraitId, TypeAliasId, - MacroDefId + MacroDefId, + ImplId ); trait Intern { -- cgit v1.2.3