diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_hir_def/src/attr.rs | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_hir_def/src/attr.rs')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index fffb22201..9efa4970c 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | use std::{ops, sync::Arc}; | 3 | use std::{ops, sync::Arc}; |
4 | 4 | ||
5 | use hir_expand::{either::Either, hygiene::Hygiene, AstId, Source}; | 5 | use either::Either; |
6 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; | ||
6 | use mbe::ast_to_token_tree; | 7 | use mbe::ast_to_token_tree; |
7 | use ra_syntax::{ | 8 | use ra_syntax::{ |
8 | ast::{self, AstNode, AttrsOwner}, | 9 | ast::{self, AstNode, AttrsOwner}, |
@@ -11,7 +12,7 @@ use ra_syntax::{ | |||
11 | use tt::Subtree; | 12 | use tt::Subtree; |
12 | 13 | ||
13 | use crate::{ | 14 | use crate::{ |
14 | db::DefDatabase, path::Path, AdtId, AstItemDef, AttrDefId, HasChildSource, HasSource, Lookup, | 15 | db::DefDatabase, path::ModPath, src::HasChildSource, src::HasSource, AdtId, AttrDefId, Lookup, |
15 | }; | 16 | }; |
16 | 17 | ||
17 | #[derive(Default, Debug, Clone, PartialEq, Eq)] | 18 | #[derive(Default, Debug, Clone, PartialEq, Eq)] |
@@ -44,8 +45,8 @@ impl Attrs { | |||
44 | AttrDefId::StructFieldId(it) => { | 45 | AttrDefId::StructFieldId(it) => { |
45 | let src = it.parent.child_source(db); | 46 | let src = it.parent.child_source(db); |
46 | match &src.value[it.local_id] { | 47 | match &src.value[it.local_id] { |
47 | Either::A(_tuple) => Attrs::default(), | 48 | Either::Left(_tuple) => Attrs::default(), |
48 | Either::B(record) => Attrs::from_attrs_owner(db, src.with_value(record)), | 49 | Either::Right(record) => Attrs::from_attrs_owner(db, src.with_value(record)), |
49 | } | 50 | } |
50 | } | 51 | } |
51 | AttrDefId::EnumVariantId(var_id) => { | 52 | AttrDefId::EnumVariantId(var_id) => { |
@@ -54,13 +55,15 @@ impl Attrs { | |||
54 | Attrs::from_attrs_owner(db, src.map(|it| it as &dyn AttrsOwner)) | 55 | Attrs::from_attrs_owner(db, src.map(|it| it as &dyn AttrsOwner)) |
55 | } | 56 | } |
56 | AttrDefId::AdtId(it) => match it { | 57 | AttrDefId::AdtId(it) => match it { |
57 | AdtId::StructId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 58 | AdtId::StructId(it) => attrs_from_loc(it.lookup(db), db), |
58 | AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 59 | AdtId::EnumId(it) => attrs_from_loc(it.lookup(db), db), |
59 | AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 60 | AdtId::UnionId(it) => attrs_from_loc(it.lookup(db), db), |
60 | }, | 61 | }, |
61 | AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 62 | AttrDefId::TraitId(it) => attrs_from_loc(it.lookup(db), db), |
62 | AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db), | 63 | AttrDefId::MacroDefId(it) => { |
63 | AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 64 | it.ast_id.map_or_else(Default::default, |ast_id| attrs_from_ast(ast_id, db)) |
65 | } | ||
66 | AttrDefId::ImplId(it) => attrs_from_loc(it.lookup(db), db), | ||
64 | AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), | 67 | AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), |
65 | AttrDefId::StaticId(it) => attrs_from_loc(it.lookup(db), db), | 68 | AttrDefId::StaticId(it) => attrs_from_loc(it.lookup(db), db), |
66 | AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), | 69 | AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), |
@@ -68,7 +71,7 @@ impl Attrs { | |||
68 | } | 71 | } |
69 | } | 72 | } |
70 | 73 | ||
71 | fn from_attrs_owner(db: &impl DefDatabase, owner: Source<&dyn AttrsOwner>) -> Attrs { | 74 | fn from_attrs_owner(db: &impl DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs { |
72 | let hygiene = Hygiene::new(db, owner.file_id); | 75 | let hygiene = Hygiene::new(db, owner.file_id); |
73 | Attrs::new(owner.value, &hygiene) | 76 | Attrs::new(owner.value, &hygiene) |
74 | } | 77 | } |
@@ -91,7 +94,7 @@ impl Attrs { | |||
91 | 94 | ||
92 | #[derive(Debug, Clone, PartialEq, Eq)] | 95 | #[derive(Debug, Clone, PartialEq, Eq)] |
93 | pub struct Attr { | 96 | pub struct Attr { |
94 | pub(crate) path: Path, | 97 | pub(crate) path: ModPath, |
95 | pub(crate) input: Option<AttrInput>, | 98 | pub(crate) input: Option<AttrInput>, |
96 | } | 99 | } |
97 | 100 | ||
@@ -103,7 +106,7 @@ pub enum AttrInput { | |||
103 | 106 | ||
104 | impl Attr { | 107 | impl Attr { |
105 | fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { | 108 | fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { |
106 | let path = Path::from_src(ast.path()?, hygiene)?; | 109 | let path = ModPath::from_src(ast.path()?, hygiene)?; |
107 | let input = match ast.input() { | 110 | let input = match ast.input() { |
108 | None => None, | 111 | None => None, |
109 | Some(ast::AttrInput::Literal(lit)) => { | 112 | Some(ast::AttrInput::Literal(lit)) => { |
@@ -157,7 +160,7 @@ where | |||
157 | N: ast::AttrsOwner, | 160 | N: ast::AttrsOwner, |
158 | D: DefDatabase, | 161 | D: DefDatabase, |
159 | { | 162 | { |
160 | let src = Source::new(src.file_id(), src.to_node(db)); | 163 | let src = InFile::new(src.file_id, src.to_node(db)); |
161 | Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) | 164 | Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) |
162 | } | 165 | } |
163 | 166 | ||