diff options
Diffstat (limited to 'crates/ra_hir/src/from_source.rs')
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 978326c74..f7411c5cf 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | use hir_def::{ | 2 | use hir_def::{ |
3 | child_by_source::ChildBySource, dyn_map::DynMap, keys, nameres::ModuleSource, AstItemDef, | 3 | child_by_source::ChildBySource, dyn_map::DynMap, keys, nameres::ModuleSource, EnumVariantId, |
4 | EnumVariantId, GenericDefId, LocationCtx, ModuleId, VariantId, | 4 | GenericDefId, ModuleId, VariantId, |
5 | }; | 5 | }; |
6 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; | 6 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
@@ -32,15 +32,19 @@ impl FromSource for Struct { | |||
32 | impl FromSource for Union { | 32 | impl FromSource for Union { |
33 | type Ast = ast::UnionDef; | 33 | type Ast = ast::UnionDef; |
34 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { | 34 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { |
35 | let id = from_source(db, src)?; | 35 | analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::UNION] |
36 | Some(Union { id }) | 36 | .get(&src) |
37 | .copied() | ||
38 | .map(Union::from) | ||
37 | } | 39 | } |
38 | } | 40 | } |
39 | impl FromSource for Enum { | 41 | impl FromSource for Enum { |
40 | type Ast = ast::EnumDef; | 42 | type Ast = ast::EnumDef; |
41 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { | 43 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { |
42 | let id = from_source(db, src)?; | 44 | analyze_container(db, src.as_ref().map(|it| it.syntax()))[keys::ENUM] |
43 | Some(Enum { id }) | 45 | .get(&src) |
46 | .copied() | ||
47 | .map(Enum::from) | ||
44 | } | 48 | } |
45 | } | 49 | } |
46 | impl FromSource for Trait { | 50 | impl FromSource for Trait { |
@@ -250,19 +254,6 @@ impl Module { | |||
250 | } | 254 | } |
251 | } | 255 | } |
252 | 256 | ||
253 | fn from_source<N, DEF>(db: &(impl DefDatabase + AstDatabase), src: InFile<N>) -> Option<DEF> | ||
254 | where | ||
255 | N: AstNode, | ||
256 | DEF: AstItemDef<N>, | ||
257 | { | ||
258 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); | ||
259 | let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?; | ||
260 | let ctx = LocationCtx::new(db, module.id, src.file_id); | ||
261 | let items = db.ast_id_map(src.file_id); | ||
262 | let item_id = items.ast_id(&src.value); | ||
263 | Some(DEF::from_ast_id(ctx, item_id)) | ||
264 | } | ||
265 | |||
266 | fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { | 257 | fn analyze_container(db: &impl DefDatabase, src: InFile<&SyntaxNode>) -> DynMap { |
267 | _analyze_container(db, src).unwrap_or_default() | 258 | _analyze_container(db, src).unwrap_or_default() |
268 | } | 259 | } |