aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-10 13:47:23 +0100
committerGitHub <[email protected]>2020-07-10 13:47:23 +0100
commit0f7770ae43dd0d97686eb85fccb38801ff30117b (patch)
tree754d726b02595db4dcc4594712e30ca97a336988 /crates/ra_hir
parent5fa8f8e3761363098c80e11842682dffcee171d8 (diff)
parent075380dd56439cdaf1967b7298e10b96b995fc07 (diff)
Merge #5292
5292: Goto type definition improvements r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/semantics.rs16
-rw-r--r--crates/ra_hir/src/source_analyzer.rs13
2 files changed, 24 insertions, 5 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 3d78f71c1..0d877e44e 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -25,7 +25,7 @@ use crate::{
25 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, 25 semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
26 source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer}, 26 source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer},
27 AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, 27 AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef,
28 Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, 28 Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, VariantDef,
29}; 29};
30use resolver::TypeNs; 30use resolver::TypeNs;
31 31
@@ -192,6 +192,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
192 self.imp.type_of_pat(pat) 192 self.imp.type_of_pat(pat)
193 } 193 }
194 194
195 pub fn type_of_self(&self, param: &ast::SelfParam) -> Option<Type> {
196 self.imp.type_of_self(param)
197 }
198
195 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 199 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
196 self.imp.resolve_method_call(call) 200 self.imp.resolve_method_call(call)
197 } 201 }
@@ -216,8 +220,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
216 self.imp.resolve_path(path) 220 self.imp.resolve_path(path)
217 } 221 }
218 222
219 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> { 223 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantDef> {
220 self.imp.resolve_variant(record_lit) 224 self.imp.resolve_variant(record_lit).map(VariantDef::from)
221 } 225 }
222 226
223 pub fn lower_path(&self, path: &ast::Path) -> Option<Path> { 227 pub fn lower_path(&self, path: &ast::Path) -> Option<Path> {
@@ -370,13 +374,17 @@ impl<'db> SemanticsImpl<'db> {
370 } 374 }
371 375
372 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> { 376 pub fn type_of_expr(&self, expr: &ast::Expr) -> Option<Type> {
373 self.analyze(expr.syntax()).type_of(self.db, &expr) 377 self.analyze(expr.syntax()).type_of_expr(self.db, &expr)
374 } 378 }
375 379
376 pub fn type_of_pat(&self, pat: &ast::Pat) -> Option<Type> { 380 pub fn type_of_pat(&self, pat: &ast::Pat) -> Option<Type> {
377 self.analyze(pat.syntax()).type_of_pat(self.db, &pat) 381 self.analyze(pat.syntax()).type_of_pat(self.db, &pat)
378 } 382 }
379 383
384 pub fn type_of_self(&self, param: &ast::SelfParam) -> Option<Type> {
385 self.analyze(param.syntax()).type_of_self(self.db, &param)
386 }
387
380 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 388 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
381 self.analyze(call.syntax()).resolve_method_call(self.db, call) 389 self.analyze(call.syntax()).resolve_method_call(self.db, call)
382 } 390 }
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 1d6c47103..f74b78b23 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -115,7 +115,7 @@ impl SourceAnalyzer {
115 Some(res) 115 Some(res)
116 } 116 }
117 117
118 pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> { 118 pub(crate) fn type_of_expr(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> {
119 let expr_id = self.expr_id(db, expr)?; 119 let expr_id = self.expr_id(db, expr)?;
120 let ty = self.infer.as_ref()?[expr_id].clone(); 120 let ty = self.infer.as_ref()?[expr_id].clone();
121 Type::new_with_resolver(db, &self.resolver, ty) 121 Type::new_with_resolver(db, &self.resolver, ty)
@@ -127,6 +127,17 @@ impl SourceAnalyzer {
127 Type::new_with_resolver(db, &self.resolver, ty) 127 Type::new_with_resolver(db, &self.resolver, ty)
128 } 128 }
129 129
130 pub(crate) fn type_of_self(
131 &self,
132 db: &dyn HirDatabase,
133 param: &ast::SelfParam,
134 ) -> Option<Type> {
135 let src = InFile { file_id: self.file_id, value: param };
136 let pat_id = self.body_source_map.as_ref()?.node_self_param(src)?;
137 let ty = self.infer.as_ref()?[pat_id].clone();
138 Type::new_with_resolver(db, &self.resolver, ty)
139 }
140
130 pub(crate) fn resolve_method_call( 141 pub(crate) fn resolve_method_call(
131 &self, 142 &self,
132 db: &dyn HirDatabase, 143 db: &dyn HirDatabase,