diff options
author | Aleksey Kladov <[email protected]> | 2019-11-20 14:39:58 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-20 14:43:03 +0000 |
commit | 64c21ed19594b323e72605ba8c5dd4c6eee433f6 (patch) | |
tree | 6b48928149607fa6396357af29abfb4eb3d4d791 /crates/ra_hir_def/src/lib.rs | |
parent | b7a36b54431ca5b746af53549a1b6e142570c7f4 (diff) |
Switch type aliases to new sources
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index b9a13776f..6052370b4 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -332,16 +332,35 @@ impl AstItemDef<ast::TraitDef> for TraitId { | |||
332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
333 | pub struct TypeAliasId(salsa::InternId); | 333 | pub struct TypeAliasId(salsa::InternId); |
334 | impl_intern_key!(TypeAliasId); | 334 | impl_intern_key!(TypeAliasId); |
335 | impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { | 335 | |
336 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self { | 336 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
337 | db.intern_type_alias(loc) | 337 | pub struct TypeAliasLoc { |
338 | pub container: TypeAliasContainerId, | ||
339 | pub ast_id: AstId<ast::TypeAliasDef>, | ||
340 | } | ||
341 | |||
342 | impl Intern for TypeAliasLoc { | ||
343 | type ID = TypeAliasId; | ||
344 | fn intern(self, db: &impl db::DefDatabase2) -> TypeAliasId { | ||
345 | db.intern_type_alias(self) | ||
338 | } | 346 | } |
339 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TypeAliasDef> { | 347 | } |
340 | db.lookup_intern_type_alias(self) | 348 | |
349 | impl Lookup for TypeAliasId { | ||
350 | type Data = TypeAliasLoc; | ||
351 | fn lookup(&self, db: &impl db::DefDatabase2) -> TypeAliasLoc { | ||
352 | db.lookup_intern_type_alias(*self) | ||
341 | } | 353 | } |
342 | } | 354 | } |
343 | 355 | ||
344 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 356 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
357 | pub enum TypeAliasContainerId { | ||
358 | ModuleId(ModuleId), | ||
359 | ImplId(ImplId), | ||
360 | TraitId(TraitId), | ||
361 | } | ||
362 | |||
363 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
345 | pub struct ImplId(salsa::InternId); | 364 | pub struct ImplId(salsa::InternId); |
346 | impl_intern_key!(ImplId); | 365 | impl_intern_key!(ImplId); |
347 | impl AstItemDef<ast::ImplBlock> for ImplId { | 366 | impl AstItemDef<ast::ImplBlock> for ImplId { |
@@ -476,6 +495,16 @@ impl HasModule for FunctionLoc { | |||
476 | } | 495 | } |
477 | } | 496 | } |
478 | 497 | ||
498 | impl HasModule for TypeAliasLoc { | ||
499 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { | ||
500 | match self.container { | ||
501 | TypeAliasContainerId::ModuleId(it) => it, | ||
502 | TypeAliasContainerId::ImplId(it) => it.module(db), | ||
503 | TypeAliasContainerId::TraitId(it) => it.module(db), | ||
504 | } | ||
505 | } | ||
506 | } | ||
507 | |||
479 | pub trait HasSource { | 508 | pub trait HasSource { |
480 | type Value; | 509 | type Value; |
481 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; | 510 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; |
@@ -489,3 +518,12 @@ impl HasSource for FunctionLoc { | |||
489 | Source::new(self.ast_id.file_id(), node) | 518 | Source::new(self.ast_id.file_id(), node) |
490 | } | 519 | } |
491 | } | 520 | } |
521 | |||
522 | impl HasSource for TypeAliasLoc { | ||
523 | type Value = ast::TypeAliasDef; | ||
524 | |||
525 | fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::TypeAliasDef> { | ||
526 | let node = self.ast_id.to_node(db); | ||
527 | Source::new(self.ast_id.file_id(), node) | ||
528 | } | ||
529 | } | ||