diff options
author | Aleksey Kladov <[email protected]> | 2019-12-12 14:11:57 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-12 14:11:57 +0000 |
commit | 56710f119b7114efac237ac36ea21730b8bd5311 (patch) | |
tree | 9e54318d6f291e3d997a9fe99554c24eeb4a47bc /crates/ra_hir/src | |
parent | f135a8ea55c0a46c67713fb3b79b5f62ada430c1 (diff) |
Move enum&union to new loc
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 29 | ||||
-rw-r--r-- | crates/ra_hir/src/has_source.rs | 6 |
3 files changed, 18 insertions, 27 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 8588aa5a3..c705d1630 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -11,7 +11,7 @@ use hir_def::{ | |||
11 | per_ns::PerNs, | 11 | per_ns::PerNs, |
12 | resolver::HasResolver, | 12 | resolver::HasResolver, |
13 | type_ref::{Mutability, TypeRef}, | 13 | type_ref::{Mutability, TypeRef}, |
14 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, | 14 | AdtId, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, |
15 | LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, | 15 | LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, |
16 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, | 16 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, |
17 | }; | 17 | }; |
@@ -309,11 +309,11 @@ impl Union { | |||
309 | } | 309 | } |
310 | 310 | ||
311 | pub fn module(self, db: &impl DefDatabase) -> Module { | 311 | pub fn module(self, db: &impl DefDatabase) -> Module { |
312 | Module { id: self.id.module(db) } | 312 | Module { id: self.id.lookup(db).container } |
313 | } | 313 | } |
314 | 314 | ||
315 | pub fn ty(self, db: &impl HirDatabase) -> Type { | 315 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
316 | Type::from_def(db, self.id.module(db).krate, self.id) | 316 | Type::from_def(db, self.id.lookup(db).container.krate, self.id) |
317 | } | 317 | } |
318 | 318 | ||
319 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { | 319 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { |
@@ -337,7 +337,7 @@ pub struct Enum { | |||
337 | 337 | ||
338 | impl Enum { | 338 | impl Enum { |
339 | pub fn module(self, db: &impl DefDatabase) -> Module { | 339 | pub fn module(self, db: &impl DefDatabase) -> Module { |
340 | Module { id: self.id.module(db) } | 340 | Module { id: self.id.lookup(db).container } |
341 | } | 341 | } |
342 | 342 | ||
343 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | 343 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { |
@@ -357,7 +357,7 @@ impl Enum { | |||
357 | } | 357 | } |
358 | 358 | ||
359 | pub fn ty(self, db: &impl HirDatabase) -> Type { | 359 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
360 | Type::from_def(db, self.id.module(db).krate, self.id) | 360 | Type::from_def(db, self.id.lookup(db).container.krate, self.id) |
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
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 | } |
diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 8f35a3fbb..72afecf26 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs | |||
@@ -4,7 +4,7 @@ use either::Either; | |||
4 | use hir_def::{ | 4 | use hir_def::{ |
5 | nameres::ModuleSource, | 5 | nameres::ModuleSource, |
6 | src::{HasChildSource, HasSource as _}, | 6 | src::{HasChildSource, HasSource as _}, |
7 | AstItemDef, Lookup, VariantId, | 7 | Lookup, VariantId, |
8 | }; | 8 | }; |
9 | use ra_syntax::ast; | 9 | use ra_syntax::ast; |
10 | 10 | ||
@@ -57,13 +57,13 @@ impl HasSource for Struct { | |||
57 | impl HasSource for Union { | 57 | impl HasSource for Union { |
58 | type Ast = ast::UnionDef; | 58 | type Ast = ast::UnionDef; |
59 | fn source(self, db: &impl DefDatabase) -> InFile<ast::UnionDef> { | 59 | fn source(self, db: &impl DefDatabase) -> InFile<ast::UnionDef> { |
60 | self.id.source(db) | 60 | self.id.lookup(db).source(db) |
61 | } | 61 | } |
62 | } | 62 | } |
63 | impl HasSource for Enum { | 63 | impl HasSource for Enum { |
64 | type Ast = ast::EnumDef; | 64 | type Ast = ast::EnumDef; |
65 | fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumDef> { | 65 | fn source(self, db: &impl DefDatabase) -> InFile<ast::EnumDef> { |
66 | self.id.source(db) | 66 | self.id.lookup(db).source(db) |
67 | } | 67 | } |
68 | } | 68 | } |
69 | impl HasSource for EnumVariant { | 69 | impl HasSource for EnumVariant { |