aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/adt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/adt.rs')
-rw-r--r--crates/ra_hir/src/adt.rs39
1 files changed, 17 insertions, 22 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 38ff1d6f6..b3843b35c 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11 11
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, 13 Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, StructField, FieldSource, Source, HasSource,
15 type_ref::TypeRef, DefDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
17 17
@@ -59,8 +59,8 @@ impl StructData {
59 db: &(impl DefDatabase + AstDatabase), 59 db: &(impl DefDatabase + AstDatabase),
60 struct_: Struct, 60 struct_: Struct,
61 ) -> Arc<StructData> { 61 ) -> Arc<StructData> {
62 let (_, struct_def) = struct_.source(db); 62 let src = struct_.source(db);
63 Arc::new(StructData::new(&*struct_def)) 63 Arc::new(StructData::new(&*src.ast))
64 } 64 }
65} 65}
66 66
@@ -72,15 +72,15 @@ impl EnumVariant {
72 pub(crate) fn source_impl( 72 pub(crate) fn source_impl(
73 &self, 73 &self,
74 db: &(impl DefDatabase + AstDatabase), 74 db: &(impl DefDatabase + AstDatabase),
75 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 75 ) -> Source<TreeArc<ast::EnumVariant>> {
76 let (file_id, enum_def) = self.parent.source(db); 76 let src = self.parent.source(db);
77 let var = variants(&*enum_def) 77 let ast = variants(&*src.ast)
78 .zip(db.enum_data(self.parent).variants.iter()) 78 .zip(db.enum_data(self.parent).variants.iter())
79 .find(|(_syntax, (id, _))| *id == self.id) 79 .find(|(_syntax, (id, _))| *id == self.id)
80 .unwrap() 80 .unwrap()
81 .0 81 .0
82 .to_owned(); 82 .to_owned();
83 (file_id, var) 83 Source { file_id: src.file_id, ast }
84 } 84 }
85 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> { 85 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
86 db.enum_data(self.parent).variants[self.id].variant_data.clone() 86 db.enum_data(self.parent).variants[self.id].variant_data.clone()
@@ -95,9 +95,9 @@ pub struct EnumData {
95 95
96impl EnumData { 96impl EnumData {
97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> { 97 pub(crate) fn enum_data_query(db: &(impl DefDatabase + AstDatabase), e: Enum) -> Arc<EnumData> {
98 let (_file_id, enum_def) = e.source(db); 98 let src = e.source(db);
99 let name = enum_def.name().map(|n| n.as_name()); 99 let name = src.ast.name().map(|n| n.as_name());
100 let variants = variants(&*enum_def) 100 let variants = variants(&*src.ast)
101 .map(|var| EnumVariantData { 101 .map(|var| EnumVariantData {
102 name: var.name().map(|it| it.as_name()), 102 name: var.name().map(|it| it.as_name()),
103 variant_data: Arc::new(VariantData::new(var.kind())), 103 variant_data: Arc::new(VariantData::new(var.kind())),
@@ -201,24 +201,19 @@ impl VariantDef {
201} 201}
202 202
203impl StructField { 203impl StructField {
204 pub(crate) fn source_impl( 204 pub(crate) fn source_impl(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<FieldSource> {
205 &self,
206 db: &(impl DefDatabase + AstDatabase),
207 ) -> (HirFileId, FieldSource) {
208 let var_data = self.parent.variant_data(db); 205 let var_data = self.parent.variant_data(db);
209 let fields = var_data.fields().unwrap(); 206 let fields = var_data.fields().unwrap();
210 let ss; 207 let ss;
211 let es; 208 let es;
212 let (file_id, struct_kind) = match self.parent { 209 let (file_id, struct_kind) = match self.parent {
213 VariantDef::Struct(s) => { 210 VariantDef::Struct(s) => {
214 let (file_id, source) = s.source(db); 211 ss = s.source(db);
215 ss = source; 212 (ss.file_id, ss.ast.kind())
216 (file_id, ss.kind())
217 } 213 }
218 VariantDef::EnumVariant(e) => { 214 VariantDef::EnumVariant(e) => {
219 let (file_id, source) = e.source(db); 215 es = e.source(db);
220 es = source; 216 (es.file_id, es.ast.kind())
221 (file_id, es.kind())
222 } 217 }
223 }; 218 };
224 219
@@ -231,12 +226,12 @@ impl StructField {
231 } 226 }
232 ast::StructKind::Unit => Vec::new(), 227 ast::StructKind::Unit => Vec::new(),
233 }; 228 };
234 let field = field_sources 229 let ast = field_sources
235 .into_iter() 230 .into_iter()
236 .zip(fields.iter()) 231 .zip(fields.iter())
237 .find(|(_syntax, (id, _))| *id == self.id) 232 .find(|(_syntax, (id, _))| *id == self.id)
238 .unwrap() 233 .unwrap()
239 .0; 234 .0;
240 (file_id, field) 235 Source { file_id, ast }
241 } 236 }
242} 237}