diff options
author | Lukas Tobias Wirth <[email protected]> | 2021-05-06 16:05:49 +0100 |
---|---|---|
committer | Lukas Tobias Wirth <[email protected]> | 2021-05-06 16:05:49 +0100 |
commit | d97a4b8e49df118a13a122225474bcbd011c0ea1 (patch) | |
tree | f1004fe3c662aaa0f386aea174a106a6ab4bdca5 /crates/hir/src | |
parent | 5b663f1b07233442a3b0b58db453504dcc51ddc9 (diff) |
Support goto_type_definition for types
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/semantics.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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> { | |||
196 | self.imp.resolve_label(lifetime) | 196 | self.imp.resolve_label(lifetime) |
197 | } | 197 | } |
198 | 198 | ||
199 | pub fn resolve_type(&self, ty: &ast::Type) -> Option<Type> { | ||
200 | self.imp.resolve_type(ty) | ||
201 | } | ||
202 | |||
199 | pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { | 203 | pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { |
200 | self.imp.type_of_expr(expr) | 204 | self.imp.type_of_expr(expr) |
201 | } | 205 | } |
@@ -476,6 +480,14 @@ impl<'db> SemanticsImpl<'db> { | |||
476 | ToDef::to_def(self, src) | 480 | ToDef::to_def(self, src) |
477 | } | 481 | } |
478 | 482 | ||
483 | fn resolve_type(&self, ty: &ast::Type) -> Option<Type> { | ||
484 | let scope = self.scope(ty.syntax()); | ||
485 | let ctx = body::LowerCtx::new(self.db.upcast(), scope.file_id); | ||
486 | let ty = hir_ty::TyLoweringContext::new(self.db, &scope.resolver) | ||
487 | .lower_ty(&crate::TypeRef::from_ast(&ctx, ty.clone())); | ||
488 | Type::new_with_resolver(self.db, &scope.resolver, ty) | ||
489 | } | ||
490 | |||
479 | fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { | 491 | fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { |
480 | self.analyze(expr.syntax()).type_of_expr(self.db, expr) | 492 | self.analyze(expr.syntax()).type_of_expr(self.db, expr) |
481 | } | 493 | } |