aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-11 13:58:00 +0100
committerAleksey Kladov <[email protected]>2019-04-11 14:29:33 +0100
commit07cc047b4ffe3049dfe95fc5cd59383336976e2d (patch)
tree69a1df4df350890544b5e6e1fcff9da68f1af351 /crates/ra_hir/src
parentb6809b6695f9c4cec82ff98d73f7ff24f96cbecf (diff)
minimize the API
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/source_binder.rs28
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)]
266pub struct SourceAnalyzer { 267pub 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
347impl 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}