From 07cc047b4ffe3049dfe95fc5cd59383336976e2d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 11 Apr 2019 15:58:00 +0300 Subject: minimize the API --- crates/ra_hir/src/source_binder.rs | 28 +++++++++------------------- crates/ra_ide_api/src/goto_definition.rs | 6 ++---- 2 files changed, 11 insertions(+), 23 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 309e33ca9..ec9af035f 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -261,7 +261,8 @@ fn try_get_resolver_for_node( } } -/// `SourceAnalyzer` +/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of +/// original source files. It should not be used inside the HIR itself. #[derive(Debug)] pub struct SourceAnalyzer { resolver: Resolver, @@ -274,7 +275,7 @@ pub enum PathResolution { /// An item Def(crate::ModuleDef), /// A local binding (only value namespace) - LocalBinding(crate::expr::PatId), + LocalBinding(Either, AstPtr>), /// A generic parameter GenericParam(u32), SelfType(crate::ImplBlock), @@ -332,25 +333,14 @@ impl SourceAnalyzer { let hir_path = crate::Path::from_ast(path)?; let res = self.resolver.resolve_path(db, &hir_path); let res = res.clone().take_types().or_else(|| res.take_values())?; - Some(res.into()) - } - - pub fn pat_syntax( - &self, - _db: &impl HirDatabase, - pat: crate::expr::PatId, - ) -> Option, AstPtr>> { - self.body_source_map.as_ref()?.pat_syntax(pat) - } -} - -impl From for PathResolution { - fn from(res: crate::Resolution) -> PathResolution { - match res { + let res = match res { crate::Resolution::Def(it) => PathResolution::Def(it), - crate::Resolution::LocalBinding(it) => PathResolution::LocalBinding(it), + crate::Resolution::LocalBinding(it) => { + PathResolution::LocalBinding(self.body_source_map.as_ref()?.pat_syntax(it)?) + } crate::Resolution::GenericParam(it) => PathResolution::GenericParam(it), crate::Resolution::SelfType(it) => PathResolution::SelfType(it), - } + }; + Some(res) } } diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 1f1a8d126..abcc682e7 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -90,10 +90,8 @@ pub(crate) fn reference_definition( match resolved { hir::PathResolution::Def(def) => return Exact(NavigationTarget::from_def(db, def)), hir::PathResolution::LocalBinding(pat) => { - if let Some(pat) = analyzer.pat_syntax(db, pat) { - let nav = NavigationTarget::from_pat(db, file_id, pat); - return Exact(nav); - } + let nav = NavigationTarget::from_pat(db, file_id, pat); + return Exact(nav); } hir::PathResolution::GenericParam(..) => { // FIXME: go to the generic param def -- cgit v1.2.3