From d97a4b8e49df118a13a122225474bcbd011c0ea1 Mon Sep 17 00:00:00 2001 From: Lukas Tobias Wirth Date: Thu, 6 May 2021 17:05:49 +0200 Subject: Support goto_type_definition for types --- crates/hir/src/semantics.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/hir') diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 62500602a..38bd376bc 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -196,6 +196,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.imp.resolve_label(lifetime) } + pub fn resolve_type(&self, ty: &ast::Type) -> Option { + self.imp.resolve_type(ty) + } + pub fn type_of_expr(&self, expr: &ast::Expr) -> Option { self.imp.type_of_expr(expr) } @@ -476,6 +480,14 @@ impl<'db> SemanticsImpl<'db> { ToDef::to_def(self, src) } + fn resolve_type(&self, ty: &ast::Type) -> Option { + let scope = self.scope(ty.syntax()); + let ctx = body::LowerCtx::new(self.db.upcast(), scope.file_id); + let ty = hir_ty::TyLoweringContext::new(self.db, &scope.resolver) + .lower_ty(&crate::TypeRef::from_ast(&ctx, ty.clone())); + Type::new_with_resolver(self.db, &scope.resolver, ty) + } + fn type_of_expr(&self, expr: &ast::Expr) -> Option { self.analyze(expr.syntax()).type_of_expr(self.db, expr) } -- cgit v1.2.3