aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorEkaterina Babshukova <[email protected]>2019-10-12 18:30:53 +0100
committerEkaterina Babshukova <[email protected]>2019-10-22 21:47:31 +0100
commit835173d065dbe1fdd7369ea49336c0b785be8cb8 (patch)
treee19916b78f4fff145ec59b790c626e2a9f538bbb /crates/ra_hir
parentd26d0ada50fd0063c03e28bc2673f9f63fd23d95 (diff)
replace trait by a bunch of functions
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/from_source.rs60
1 files changed, 2 insertions, 58 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index e09414ca3..f80d8eb5f 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -11,9 +11,8 @@ use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 11 db::{AstDatabase, DefDatabase, HirDatabase},
12 ids::{AstItemDef, LocationCtx}, 12 ids::{AstItemDef, LocationCtx},
13 name::AsName, 13 name::AsName,
14 AssocItem, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, 14 Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module,
15 Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, 15 ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef,
16 VariantDef,
17}; 16};
18 17
19pub trait FromSource: Sized { 18pub trait FromSource: Sized {
@@ -130,61 +129,6 @@ impl FromSource for StructField {
130 } 129 }
131} 130}
132 131
133impl FromSource for AssocItem {
134 type Ast = ast::ImplItem;
135 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
136 macro_rules! def {
137 ($kind:ident, $ast:ident) => {
138 $kind::from_source(db, Source { file_id: src.file_id, ast: $ast })
139 .and_then(|it| Some(AssocItem::from(it)))
140 };
141 }
142
143 match src.ast {
144 ast::ImplItem::FnDef(f) => def!(Function, f),
145 ast::ImplItem::ConstDef(c) => def!(Const, c),
146 ast::ImplItem::TypeAliasDef(a) => def!(TypeAlias, a),
147 }
148 }
149}
150
151// not fully matched
152impl FromSource for ModuleDef {
153 type Ast = ast::ModuleItem;
154 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
155 macro_rules! def {
156 ($kind:ident, $ast:ident) => {
157 $kind::from_source(db, Source { file_id: src.file_id, ast: $ast })
158 .and_then(|it| Some(ModuleDef::from(it)))
159 };
160 }
161
162 match src.ast {
163 ast::ModuleItem::FnDef(f) => def!(Function, f),
164 ast::ModuleItem::ConstDef(c) => def!(Const, c),
165 ast::ModuleItem::TypeAliasDef(a) => def!(TypeAlias, a),
166 ast::ModuleItem::TraitDef(t) => def!(Trait, t),
167 ast::ModuleItem::StaticDef(s) => def!(Static, s),
168 ast::ModuleItem::StructDef(s) => {
169 let src = Source { file_id: src.file_id, ast: s };
170 let s = Struct::from_source(db, src)?;
171 Some(ModuleDef::Adt(s.into()))
172 }
173 ast::ModuleItem::EnumDef(e) => {
174 let src = Source { file_id: src.file_id, ast: e };
175 let e = Enum::from_source(db, src)?;
176 Some(ModuleDef::Adt(e.into()))
177 }
178 ast::ModuleItem::Module(ref m) if !m.has_semi() => {
179 let src = Source { file_id: src.file_id, ast: ModuleSource::Module(m.clone()) };
180 let module = Module::from_definition(db, src)?;
181 Some(ModuleDef::Module(module))
182 }
183 _ => None,
184 }
185 }
186}
187
188// FIXME: simplify it 132// FIXME: simplify it
189impl ModuleSource { 133impl ModuleSource {
190 pub fn from_position( 134 pub fn from_position(