diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 6 |
2 files changed, 11 insertions, 23 deletions
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( | |||
261 | } | 261 | } |
262 | } | 262 | } |
263 | 263 | ||
264 | /// `SourceAnalyzer` | 264 | /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of |
265 | /// original source files. It should not be used inside the HIR itself. | ||
265 | #[derive(Debug)] | 266 | #[derive(Debug)] |
266 | pub struct SourceAnalyzer { | 267 | pub struct SourceAnalyzer { |
267 | resolver: Resolver, | 268 | resolver: Resolver, |
@@ -274,7 +275,7 @@ pub enum PathResolution { | |||
274 | /// An item | 275 | /// An item |
275 | Def(crate::ModuleDef), | 276 | Def(crate::ModuleDef), |
276 | /// A local binding (only value namespace) | 277 | /// A local binding (only value namespace) |
277 | LocalBinding(crate::expr::PatId), | 278 | LocalBinding(Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>), |
278 | /// A generic parameter | 279 | /// A generic parameter |
279 | GenericParam(u32), | 280 | GenericParam(u32), |
280 | SelfType(crate::ImplBlock), | 281 | SelfType(crate::ImplBlock), |
@@ -332,25 +333,14 @@ impl SourceAnalyzer { | |||
332 | let hir_path = crate::Path::from_ast(path)?; | 333 | let hir_path = crate::Path::from_ast(path)?; |
333 | let res = self.resolver.resolve_path(db, &hir_path); | 334 | let res = self.resolver.resolve_path(db, &hir_path); |
334 | let res = res.clone().take_types().or_else(|| res.take_values())?; | 335 | let res = res.clone().take_types().or_else(|| res.take_values())?; |
335 | Some(res.into()) | 336 | let res = match res { |
336 | } | ||
337 | |||
338 | pub fn pat_syntax( | ||
339 | &self, | ||
340 | _db: &impl HirDatabase, | ||
341 | pat: crate::expr::PatId, | ||
342 | ) -> Option<Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>> { | ||
343 | self.body_source_map.as_ref()?.pat_syntax(pat) | ||
344 | } | ||
345 | } | ||
346 | |||
347 | impl From<crate::Resolution> for PathResolution { | ||
348 | fn from(res: crate::Resolution) -> PathResolution { | ||
349 | match res { | ||
350 | crate::Resolution::Def(it) => PathResolution::Def(it), | 337 | crate::Resolution::Def(it) => PathResolution::Def(it), |
351 | crate::Resolution::LocalBinding(it) => PathResolution::LocalBinding(it), | 338 | crate::Resolution::LocalBinding(it) => { |
339 | PathResolution::LocalBinding(self.body_source_map.as_ref()?.pat_syntax(it)?) | ||
340 | } | ||
352 | crate::Resolution::GenericParam(it) => PathResolution::GenericParam(it), | 341 | crate::Resolution::GenericParam(it) => PathResolution::GenericParam(it), |
353 | crate::Resolution::SelfType(it) => PathResolution::SelfType(it), | 342 | crate::Resolution::SelfType(it) => PathResolution::SelfType(it), |
354 | } | 343 | }; |
344 | Some(res) | ||
355 | } | 345 | } |
356 | } | 346 | } |
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( | |||
90 | match resolved { | 90 | match resolved { |
91 | hir::PathResolution::Def(def) => return Exact(NavigationTarget::from_def(db, def)), | 91 | hir::PathResolution::Def(def) => return Exact(NavigationTarget::from_def(db, def)), |
92 | hir::PathResolution::LocalBinding(pat) => { | 92 | hir::PathResolution::LocalBinding(pat) => { |
93 | if let Some(pat) = analyzer.pat_syntax(db, pat) { | 93 | let nav = NavigationTarget::from_pat(db, file_id, pat); |
94 | let nav = NavigationTarget::from_pat(db, file_id, pat); | 94 | return Exact(nav); |
95 | return Exact(nav); | ||
96 | } | ||
97 | } | 95 | } |
98 | hir::PathResolution::GenericParam(..) => { | 96 | hir::PathResolution::GenericParam(..) => { |
99 | // FIXME: go to the generic param def | 97 | // FIXME: go to the generic param def |