diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/source_analyzer.rs | 32 |
2 files changed, 9 insertions, 25 deletions
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 004a2185f..4a85e7e36 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -47,7 +47,7 @@ pub use crate::{ | |||
47 | }, | 47 | }, |
48 | has_source::HasSource, | 48 | has_source::HasSource, |
49 | semantics::{original_range, Semantics, SemanticsScope}, | 49 | semantics::{original_range, Semantics, SemanticsScope}, |
50 | source_analyzer::{PathResolution, ScopeEntryWithSyntax}, | 50 | source_analyzer::PathResolution, |
51 | }; | 51 | }; |
52 | 52 | ||
53 | pub use hir_def::{ | 53 | pub use hir_def::{ |
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index bff1ecd14..b655e2c32 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -25,8 +25,8 @@ use ra_syntax::{ | |||
25 | }; | 25 | }; |
26 | 26 | ||
27 | use crate::{ | 27 | use crate::{ |
28 | db::HirDatabase, Adt, Const, EnumVariant, Function, Local, MacroDef, Name, Path, Static, | 28 | db::HirDatabase, Adt, Const, EnumVariant, Function, Local, MacroDef, Path, Static, Struct, |
29 | Struct, Trait, Type, TypeAlias, TypeParam, | 29 | Trait, Type, TypeAlias, TypeParam, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of | 32 | /// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of |
@@ -53,22 +53,6 @@ pub enum PathResolution { | |||
53 | AssocItem(crate::AssocItem), | 53 | AssocItem(crate::AssocItem), |
54 | } | 54 | } |
55 | 55 | ||
56 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
57 | pub struct ScopeEntryWithSyntax { | ||
58 | pub(crate) name: Name, | ||
59 | pub(crate) ptr: Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>, | ||
60 | } | ||
61 | |||
62 | impl ScopeEntryWithSyntax { | ||
63 | pub fn name(&self) -> &Name { | ||
64 | &self.name | ||
65 | } | ||
66 | |||
67 | pub fn ptr(&self) -> Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>> { | ||
68 | self.ptr | ||
69 | } | ||
70 | } | ||
71 | |||
72 | #[derive(Debug)] | 56 | #[derive(Debug)] |
73 | pub struct ReferenceDescriptor { | 57 | pub struct ReferenceDescriptor { |
74 | pub range: TextRange, | 58 | pub range: TextRange, |
@@ -235,16 +219,16 @@ impl SourceAnalyzer { | |||
235 | resolve_hir_path(db, &self.resolver, &hir_path) | 219 | resolve_hir_path(db, &self.resolver, &hir_path) |
236 | } | 220 | } |
237 | 221 | ||
238 | fn resolve_local_name(&self, name_ref: &ast::NameRef) -> Option<ScopeEntryWithSyntax> { | 222 | fn resolve_local_name( |
223 | &self, | ||
224 | name_ref: &ast::NameRef, | ||
225 | ) -> Option<Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>> { | ||
239 | let name = name_ref.as_name(); | 226 | let name = name_ref.as_name(); |
240 | let source_map = self.body_source_map.as_ref()?; | 227 | let source_map = self.body_source_map.as_ref()?; |
241 | let scopes = self.scopes.as_ref()?; | 228 | let scopes = self.scopes.as_ref()?; |
242 | let scope = scope_for(scopes, source_map, InFile::new(self.file_id, name_ref.syntax()))?; | 229 | let scope = scope_for(scopes, source_map, InFile::new(self.file_id, name_ref.syntax()))?; |
243 | let entry = scopes.resolve_name_in_scope(scope, &name)?; | 230 | let entry = scopes.resolve_name_in_scope(scope, &name)?; |
244 | Some(ScopeEntryWithSyntax { | 231 | Some(source_map.pat_syntax(entry.pat())?.value) |
245 | name: entry.name().clone(), | ||
246 | ptr: source_map.pat_syntax(entry.pat())?.value, | ||
247 | }) | ||
248 | } | 232 | } |
249 | 233 | ||
250 | // FIXME: we only use this in `inline_local_variable` assist, ideally, we | 234 | // FIXME: we only use this in `inline_local_variable` assist, ideally, we |
@@ -258,7 +242,7 @@ impl SourceAnalyzer { | |||
258 | .filter_map(ast::NameRef::cast) | 242 | .filter_map(ast::NameRef::cast) |
259 | .filter(|name_ref| match self.resolve_local_name(&name_ref) { | 243 | .filter(|name_ref| match self.resolve_local_name(&name_ref) { |
260 | None => false, | 244 | None => false, |
261 | Some(entry) => entry.ptr() == ptr, | 245 | Some(d_ptr) => d_ptr == ptr, |
262 | }) | 246 | }) |
263 | .map(|name_ref| ReferenceDescriptor { | 247 | .map(|name_ref| ReferenceDescriptor { |
264 | name: name_ref.text().to_string(), | 248 | name: name_ref.text().to_string(), |