aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/item_tree.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-06-25 13:39:27 +0100
committerJonas Schievink <[email protected]>2020-06-25 13:39:27 +0100
commitd84b3ff6a1c42df0e349dc8ec3fc08e8c1251777 (patch)
treec39b8534ceaaeb34ec99c973afa738f6f44dd6a4 /crates/ra_hir_def/src/item_tree.rs
parent9ba772657950cb8353f37bc2576b78c4f0c8996f (diff)
Collect field/variant attrs in ItemTree
Diffstat (limited to 'crates/ra_hir_def/src/item_tree.rs')
-rw-r--r--crates/ra_hir_def/src/item_tree.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs
index f99e05432..fd874750e 100644
--- a/crates/ra_hir_def/src/item_tree.rs
+++ b/crates/ra_hir_def/src/item_tree.rs
@@ -178,8 +178,8 @@ impl ItemTree {
178 self.attrs.get(&AttrOwner::TopLevel).unwrap_or(&Attrs::EMPTY) 178 self.attrs.get(&AttrOwner::TopLevel).unwrap_or(&Attrs::EMPTY)
179 } 179 }
180 180
181 pub fn attrs(&self, of: ModItem) -> &Attrs { 181 pub fn attrs(&self, of: AttrOwner) -> &Attrs {
182 self.attrs.get(&AttrOwner::ModItem(of)).unwrap_or(&Attrs::EMPTY) 182 self.attrs.get(&of).unwrap_or(&Attrs::EMPTY)
183 } 183 }
184 184
185 /// Returns the lowered inner items that `ast` corresponds to. 185 /// Returns the lowered inner items that `ast` corresponds to.
@@ -282,15 +282,32 @@ struct ItemTreeData {
282} 282}
283 283
284#[derive(Debug, Eq, PartialEq, Hash)] 284#[derive(Debug, Eq, PartialEq, Hash)]
285enum AttrOwner { 285pub enum AttrOwner {
286 /// Attributes on an item. 286 /// Attributes on an item.
287 ModItem(ModItem), 287 ModItem(ModItem),
288 /// Inner attributes of the source file. 288 /// Inner attributes of the source file.
289 TopLevel, 289 TopLevel,
290
291 Variant(Idx<Variant>),
292 Field(Idx<Field>),
290 // FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`. 293 // FIXME: Store variant and field attrs, and stop reparsing them in `attrs_query`.
291} 294}
292 295
293/// Trait implemented by all nodes in the item tree. 296macro_rules! from_attrs {
297 ( $( $var:ident($t:ty) ),+ ) => {
298 $(
299 impl From<$t> for AttrOwner {
300 fn from(t: $t) -> AttrOwner {
301 AttrOwner::$var(t)
302 }
303 }
304 )+
305 };
306}
307
308from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>));
309
310/// Trait implemented by all item nodes in the item tree.
294pub trait ItemTreeNode: Clone { 311pub trait ItemTreeNode: Clone {
295 type Source: AstNode + Into<ast::ModuleItem>; 312 type Source: AstNode + Into<ast::ModuleItem>;
296 313