aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-06 23:28:35 +0100
committerGitHub <[email protected]>2021-05-06 23:28:35 +0100
commita8da2ca3a189a3f9a422c38d0a26298dc0a9ce6f (patch)
tree9a5af005c063062dc7b5ff27c9729830626be73d /crates
parent0ee945e289c438e87d4701401059e8c407710e7b (diff)
parentd97a4b8e49df118a13a122225474bcbd011c0ea1 (diff)
Merge #8745
8745: Support goto_type_definition for types r=matklad a=Veykril I'm unsure if the approach of lowering an `ast::Type` to a `hir::Type` is a good idea, it seems fine to me at least. Fixes #2882 Co-authored-by: Lukas Tobias Wirth <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/semantics.rs12
-rw-r--r--crates/ide/src/goto_type_definition.rs12
2 files changed, 24 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 }
diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs
index 9d34b109b..f3284bb96 100644
--- a/crates/ide/src/goto_type_definition.rs
+++ b/crates/ide/src/goto_type_definition.rs
@@ -30,6 +30,7 @@ pub(crate) fn goto_type_definition(
30 ast::Expr(it) => sema.type_of_expr(&it)?, 30 ast::Expr(it) => sema.type_of_expr(&it)?,
31 ast::Pat(it) => sema.type_of_pat(&it)?, 31 ast::Pat(it) => sema.type_of_pat(&it)?,
32 ast::SelfParam(it) => sema.type_of_self(&it)?, 32 ast::SelfParam(it) => sema.type_of_self(&it)?,
33 ast::Type(it) => sema.resolve_type(&it)?,
33 _ => return None, 34 _ => return None,
34 } 35 }
35 }; 36 };
@@ -149,4 +150,15 @@ impl Foo {
149"#, 150"#,
150 ) 151 )
151 } 152 }
153
154 #[test]
155 fn goto_def_for_type_fallback() {
156 check(
157 r#"
158struct Foo;
159 //^^^
160impl Foo$0 {}
161"#,
162 )
163 }
152} 164}