diff options
author | Aleksey Kladov <[email protected]> | 2019-11-23 09:01:56 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-23 09:01:56 +0000 |
commit | 1a9986496387544c048475765ac64e83518437af (patch) | |
tree | e2316c48dff66016162a13b0b82a9b01655e485f /crates/ra_hir_def/src | |
parent | 552ba868afc8f72202ac834d07bbeb330aca007d (diff) |
Use attrs rather than syntax for lang items
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 4 |
2 files changed, 20 insertions, 8 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)] |
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 { | |||
489 | TraitId(TraitId), | 489 | TraitId(TraitId), |
490 | TypeAliasId(TypeAliasId), | 490 | TypeAliasId(TypeAliasId), |
491 | MacroDefId(MacroDefId), | 491 | MacroDefId(MacroDefId), |
492 | ImplId(ImplId), | ||
492 | } | 493 | } |
493 | 494 | ||
494 | impl_froms!( | 495 | impl_froms!( |
@@ -501,7 +502,8 @@ impl_froms!( | |||
501 | FunctionId, | 502 | FunctionId, |
502 | TraitId, | 503 | TraitId, |
503 | TypeAliasId, | 504 | TypeAliasId, |
504 | MacroDefId | 505 | MacroDefId, |
506 | ImplId | ||
505 | ); | 507 | ); |
506 | 508 | ||
507 | trait Intern { | 509 | trait Intern { |