From b85042601d69d1c592b731430ef0e445c39fda56 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Jul 2020 14:08:35 +0200 Subject: Goto type definition works for self --- crates/ra_hir/src/semantics.rs | 9 +++++++++ crates/ra_hir/src/source_analyzer.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+) (limited to 'crates/ra_hir/src') 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> { self.imp.type_of_pat(pat) } + pub fn type_of_self(&self, param: &ast::SelfParam) -> Option { + self.imp.type_of_self(param) + } + pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option { self.imp.resolve_method_call(call) } @@ -216,6 +220,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.imp.resolve_path(path) } + // TODO: id pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option { self.imp.resolve_variant(record_lit) } @@ -377,6 +382,10 @@ impl<'db> SemanticsImpl<'db> { self.analyze(pat.syntax()).type_of_pat(self.db, &pat) } + pub fn type_of_self(&self, param: &ast::SelfParam) -> Option { + self.analyze(param.syntax()).type_of_self(self.db, ¶m) + } + pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option { self.analyze(call.syntax()).resolve_method_call(self.db, call) } 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 { Some(res) } + // TODO: rename pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option { let expr_id = self.expr_id(db, expr)?; let ty = self.infer.as_ref()?[expr_id].clone(); @@ -127,6 +128,17 @@ impl SourceAnalyzer { Type::new_with_resolver(db, &self.resolver, ty) } + pub(crate) fn type_of_self( + &self, + db: &dyn HirDatabase, + param: &ast::SelfParam, + ) -> Option { + let src = InFile { file_id: self.file_id, value: param }; + let pat_id = self.body_source_map.as_ref()?.node_self_param(src)?; + let ty = self.infer.as_ref()?[pat_id].clone(); + Type::new_with_resolver(db, &self.resolver, ty) + } + pub(crate) fn resolve_method_call( &self, db: &dyn HirDatabase, -- cgit v1.2.3 From 9c54537ecf4694d02f45c7ca0a3828c08c0a0efd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Jul 2020 14:09:31 +0200 Subject: Rename --- crates/ra_hir/src/semantics.rs | 2 +- crates/ra_hir/src/source_analyzer.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 6b6c5e494..4677eb561 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -375,7 +375,7 @@ impl<'db> SemanticsImpl<'db> { } pub fn type_of_expr(&self, expr: &ast::Expr) -> Option { - self.analyze(expr.syntax()).type_of(self.db, &expr) + self.analyze(expr.syntax()).type_of_expr(self.db, &expr) } pub fn type_of_pat(&self, pat: &ast::Pat) -> Option { diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 1f1bdc0d8..f74b78b23 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs @@ -115,8 +115,7 @@ impl SourceAnalyzer { Some(res) } - // TODO: rename - pub(crate) fn type_of(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option { + pub(crate) fn type_of_expr(&self, db: &dyn HirDatabase, expr: &ast::Expr) -> Option { let expr_id = self.expr_id(db, expr)?; let ty = self.infer.as_ref()?[expr_id].clone(); Type::new_with_resolver(db, &self.resolver, ty) -- cgit v1.2.3 From f4147f6a341bda8f4a181a096b7dd726fc2d6b31 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Jul 2020 14:11:31 +0200 Subject: Dont expose ID --- crates/ra_hir/src/semantics.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/semantics.rs b/crates/ra_hir/src/semantics.rs index 4677eb561..0d877e44e 100644 --- a/crates/ra_hir/src/semantics.rs +++ b/crates/ra_hir/src/semantics.rs @@ -25,7 +25,7 @@ use crate::{ semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx}, source_analyzer::{resolve_hir_path, resolve_hir_path_qualifier, SourceAnalyzer}, AssocItem, Field, Function, HirFileId, ImplDef, InFile, Local, MacroDef, Module, ModuleDef, - Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, + Name, Origin, Path, ScopeDef, Trait, Type, TypeAlias, TypeParam, VariantDef, }; use resolver::TypeNs; @@ -220,9 +220,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> { self.imp.resolve_path(path) } - // TODO: id - pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option { - self.imp.resolve_variant(record_lit) + pub fn resolve_variant(&self, record_lit: ast::RecordLit) -> Option { + self.imp.resolve_variant(record_lit).map(VariantDef::from) } pub fn lower_path(&self, path: &ast::Path) -> Option { -- cgit v1.2.3