aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/references.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-13 12:17:48 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-13 12:17:48 +0100
commit8887782c4ab97d22f3d5c10e142407e4371c5c61 (patch)
tree80b60b2c0c2f6104b98e16648b95d99d9b1d3463 /crates/ra_ide_api/src/references.rs
parent34a05b7fea4add78446b2d93a64538982abacb9f (diff)
parent2facb5e061971afbf6bd2fabe3966d5de9d46489 (diff)
Merge #1129
1129: introduce SourceAnalyzer API for ides r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/references.rs')
-rw-r--r--crates/ra_ide_api/src/references.rs20
1 files changed, 8 insertions, 12 deletions
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs
index 3e30e047c..9f655d83c 100644
--- a/crates/ra_ide_api/src/references.rs
+++ b/crates/ra_ide_api/src/references.rs
@@ -61,11 +61,10 @@ pub(crate) fn find_all_refs(
61 position: FilePosition, 61 position: FilePosition,
62) -> Option<ReferenceSearchResult> { 62) -> Option<ReferenceSearchResult> {
63 let file = db.parse(position.file_id); 63 let file = db.parse(position.file_id);
64 let (binding, descr) = find_binding(db, &file, position)?; 64 let (binding, analyzer) = find_binding(db, &file, position)?;
65 let declaration = NavigationTarget::from_bind_pat(position.file_id, binding); 65 let declaration = NavigationTarget::from_bind_pat(position.file_id, binding);
66 66
67 let references = descr 67 let references = analyzer
68 .scopes(db)
69 .find_all_refs(binding) 68 .find_all_refs(binding)
70 .into_iter() 69 .into_iter()
71 .map(move |ref_desc| FileRange { file_id: position.file_id, range: ref_desc.range }) 70 .map(move |ref_desc| FileRange { file_id: position.file_id, range: ref_desc.range })
@@ -77,21 +76,18 @@ pub(crate) fn find_all_refs(
77 db: &RootDatabase, 76 db: &RootDatabase,
78 source_file: &'a SourceFile, 77 source_file: &'a SourceFile,
79 position: FilePosition, 78 position: FilePosition,
80 ) -> Option<(&'a ast::BindPat, hir::Function)> { 79 ) -> Option<(&'a ast::BindPat, hir::SourceAnalyzer)> {
81 let syntax = source_file.syntax(); 80 let syntax = source_file.syntax();
82 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { 81 if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) {
83 let descr = 82 let analyzer = hir::SourceAnalyzer::new(db, position.file_id, binding.syntax(), None);
84 source_binder::function_from_child_node(db, position.file_id, binding.syntax())?; 83 return Some((binding, analyzer));
85 return Some((binding, descr));
86 }; 84 };
87 let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?; 85 let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?;
88 let descr = 86 let analyzer = hir::SourceAnalyzer::new(db, position.file_id, name_ref.syntax(), None);
89 source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?; 87 let resolved = analyzer.resolve_local_name(name_ref)?;
90 let scope = descr.scopes(db);
91 let resolved = scope.resolve_local_name(name_ref)?;
92 if let Either::A(ptr) = resolved.ptr() { 88 if let Either::A(ptr) = resolved.ptr() {
93 if let ast::PatKind::BindPat(binding) = ptr.to_node(source_file).kind() { 89 if let ast::PatKind::BindPat(binding) = ptr.to_node(source_file).kind() {
94 return Some((binding, descr)); 90 return Some((binding, analyzer));
95 } 91 }
96 } 92 }
97 None 93 None