From 8c4919c9fdfb2333fd798cd7d531f4264c939322 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Jul 2020 12:45:30 +0200 Subject: Fix goto definition for type alias type parameters closes https://github.com/rust-analyzer/rust-analyzer/issues/5042 --- crates/ra_hir/src/semantics.rs | 1 + crates/ra_hir/src/semantics/source_to_def.rs | 7 +++++++ crates/ra_ide/src/goto_definition.rs | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 97125b32a..155b666d7 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -485,6 +485,7 @@ impl<'db> SemanticsImpl<'db> { ChildContainer::ModuleId(it) => it.resolver(self.db.upcast()), ChildContainer::EnumId(it) => it.resolver(self.db.upcast()), ChildContainer::VariantId(it) => it.resolver(self.db.upcast()), + ChildContainer::TypeAliasId(it) => it.resolver(self.db.upcast()), ChildContainer::GenericDefId(it) => it.resolver(self.db.upcast()), }; SourceAnalyzer::new_for_resolver(resolver, src) diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 8af64fdc1..0e1d92fb3 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -194,6 +194,10 @@ impl SourceToDefCtx<'_, '_> { let def = self.const_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, + ast::TypeAliasDef(it) => { + let def = self.type_alias_to_def(container.with_value(it))?; + def.into() + }, _ => continue, } }; @@ -246,6 +250,7 @@ pub(crate) enum ChildContainer { ImplId(ImplId), EnumId(EnumId), VariantId(VariantId), + TypeAliasId(TypeAliasId), /// XXX: this might be the same def as, for example an `EnumId`. However, /// here the children generic parameters, and not, eg enum variants. GenericDefId(GenericDefId), @@ -258,6 +263,7 @@ impl_froms! { ImplId, EnumId, VariantId, + TypeAliasId, GenericDefId } @@ -271,6 +277,7 @@ impl ChildContainer { ChildContainer::ImplId(it) => it.child_by_source(db), ChildContainer::EnumId(it) => it.child_by_source(db), ChildContainer::VariantId(it) => it.child_by_source(db), + ChildContainer::TypeAliasId(_) => DynMap::default(), ChildContainer::GenericDefId(it) => it.child_by_source(db), } } diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 8fc33d031..f575d738f 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -856,4 +856,14 @@ impl Foo { "#, ); } + + #[test] + fn goto_def_for_type_alias_generic_parameter() { + check( + r#" +type Alias = T<|>; + //^ +"#, + ) + } } -- cgit v1.2.3