aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/from_source.rs40
1 files changed, 1 insertions, 39 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index e09414ca3..df61c227a 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -12,8 +12,7 @@ use crate::{
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 AssocItem, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock,
15 Module, ModuleDef, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, 15 Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef,
16 VariantDef,
17}; 16};
18 17
19pub trait FromSource: Sized { 18pub trait FromSource: Sized {
@@ -148,43 +147,6 @@ impl FromSource for AssocItem {
148 } 147 }
149} 148}
150 149
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 150// FIXME: simplify it
189impl ModuleSource { 151impl ModuleSource {
190 pub fn from_position( 152 pub fn from_position(