aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/attr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/attr.rs')
-rw-r--r--crates/ra_hir_def/src/attr.rs24
1 files changed, 17 insertions, 7 deletions
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 {
53 } 53 }
54 } 54 }
55 } 55 }
56 AttrDefId::AdtId(it) => match it {
57 AdtId::StructId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db),
58 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
59 AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db),
60 },
61 AttrDefId::EnumVariantId(it) => { 56 AttrDefId::EnumVariantId(it) => {
62 let src = it.parent.child_source(db); 57 let src = it.parent.child_source(db);
63 let hygiene = Hygiene::new(db, src.file_id); 58 let hygiene = Hygiene::new(db, src.file_id);
64 Attr::from_attrs_owner(&src.value[it.local_id], &hygiene) 59 Attr::from_attrs_owner(&src.value[it.local_id], &hygiene)
65 } 60 }
61 AttrDefId::AdtId(it) => match it {
62 AdtId::StructId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db),
63 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
64 AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db),
65 },
66 AttrDefId::StaticId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 66 AttrDefId::StaticId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
67 AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
68 AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db),
69 AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
67 AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), 70 AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db),
68 AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), 71 AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db),
69 AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
70 AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db), 72 AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db),
71 AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db),
72 } 73 }
73 } 74 }
74 75
75 pub fn has_atom(&self, atom: &str) -> bool { 76 pub fn has_atom(&self, atom: &str) -> bool {
76 self.iter().any(|it| it.is_simple_atom(atom)) 77 self.iter().any(|it| it.is_simple_atom(atom))
77 } 78 }
79
80 pub fn find_string_value(&self, key: &str) -> Option<SmolStr> {
81 self.iter().filter(|attr| attr.is_simple_atom(key)).find_map(|attr| {
82 match attr.input.as_ref()? {
83 AttrInput::Literal(it) => Some(it.clone()),
84 _ => None,
85 }
86 })
87 }
78} 88}
79 89
80#[derive(Debug, Clone, PartialEq, Eq)] 90#[derive(Debug, Clone, PartialEq, Eq)]