diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 28 |
1 files changed, 9 insertions, 19 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 | } |