aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-10 13:08:35 +0100
committerAleksey Kladov <[email protected]>2020-07-10 13:08:35 +0100
commitb85042601d69d1c592b731430ef0e445c39fda56 (patch)
tree74d4a37d0127446bb4725ee9f1d3eea05e7601a3 /crates/ra_hir/src
parent5fa8f8e3761363098c80e11842682dffcee171d8 (diff)
Goto type definition works for self
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/semantics.rs9
-rw-r--r--crates/ra_hir/src/source_analyzer.rs12
2 files changed, 21 insertions, 0 deletions
diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs
index 3d78f71c1..6b6c5e494 100644
--- a/crates/ra_hir/src/semantics.rs
+++ b/crates/ra_hir/src/semantics.rs
@@ -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,6 +220,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
216 self.imp.resolve_path(path) 220 self.imp.resolve_path(path)
217 } 221 }
218 222
223 // TODO: id
219 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> { 224 pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option<VariantId> {
220 self.imp.resolve_variant(record_lit) 225 self.imp.resolve_variant(record_lit)
221 } 226 }
@@ -377,6 +382,10 @@ impl<'db> SemanticsImpl<'db> {
377 self.analyze(pat.syntax()).type_of_pat(self.db, &pat) 382 self.analyze(pat.syntax()).type_of_pat(self.db, &pat)
378 } 383 }
379 384
385 pub fn type_of_self(&self, param: &ast::SelfParam) -> Option<Type> {
386 self.analyze(param.syntax()).type_of_self(self.db, &param)
387 }
388
380 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { 389 pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> {
381 self.analyze(call.syntax()).resolve_method_call(self.db, call) 390 self.analyze(call.syntax()).resolve_method_call(self.db, call)
382 } 391 }
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs
index 1d6c47103..1f1bdc0d8 100644
--- a/crates/ra_hir/src/source_analyzer.rs
+++ b/crates/ra_hir/src/source_analyzer.rs
@@ -115,6 +115,7 @@ impl SourceAnalyzer {
115 Some(res) 115 Some(res)
116 } 116 }
117 117
118 // TODO: rename
118 pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> { 119 pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option<Type> {
119 let expr_id = self.expr_id(db, expr)?; 120 let expr_id = self.expr_id(db, expr)?;
120 let ty = self.infer.as_ref()?[expr_id].clone(); 121 let ty = self.infer.as_ref()?[expr_id].clone();
@@ -127,6 +128,17 @@ impl SourceAnalyzer {
127 Type::new_with_resolver(db, &self.resolver, ty) 128 Type::new_with_resolver(db, &self.resolver, ty)
128 } 129 }
129 130
131 pub(crate) fn type_of_self(
132 &self,
133 db: &dyn HirDatabase,
134 param: &ast::SelfParam,
135 ) -> Option<Type> {
136 let src = InFile { file_id: self.file_id, value: param };
137 let pat_id = self.body_source_map.as_ref()?.node_self_param(src)?;
138 let ty = self.infer.as_ref()?[pat_id].clone();
139 Type::new_with_resolver(db, &self.resolver, ty)
140 }
141
130 pub(crate) fn resolve_method_call( 142 pub(crate) fn resolve_method_call(
131 &self, 143 &self,
132 db: &dyn HirDatabase, 144 db: &dyn HirDatabase,