diff options
Diffstat (limited to 'crates/ra_ide_api/src/imp.rs')
-rw-r--r-- | crates/ra_ide_api/src/imp.rs | 54 |
1 files changed, 1 insertions, 53 deletions
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index dea71740c..435cc7d4b 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs | |||
@@ -2,11 +2,7 @@ use hir::{ | |||
2 | self, Problem, source_binder | 2 | self, Problem, source_binder |
3 | }; | 3 | }; |
4 | use ra_ide_api_light::{self, LocalEdit, Severity}; | 4 | use ra_ide_api_light::{self, LocalEdit, Severity}; |
5 | use ra_syntax::{ | 5 | use ra_syntax::ast; |
6 | algo::find_node_at_offset, ast::{self, NameOwner}, AstNode, | ||
7 | SourceFile, | ||
8 | TextRange, | ||
9 | }; | ||
10 | use ra_db::SourceDatabase; | 6 | use ra_db::SourceDatabase; |
11 | 7 | ||
12 | use crate::{ | 8 | use crate::{ |
@@ -16,54 +12,6 @@ use crate::{ | |||
16 | }; | 12 | }; |
17 | 13 | ||
18 | impl db::RootDatabase { | 14 | impl db::RootDatabase { |
19 | pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { | ||
20 | let file = self.parse(position.file_id); | ||
21 | // Find the binding associated with the offset | ||
22 | let (binding, descr) = match find_binding(self, &file, position) { | ||
23 | None => return Vec::new(), | ||
24 | Some(it) => it, | ||
25 | }; | ||
26 | |||
27 | let mut ret = binding | ||
28 | .name() | ||
29 | .into_iter() | ||
30 | .map(|name| (position.file_id, name.syntax().range())) | ||
31 | .collect::<Vec<_>>(); | ||
32 | ret.extend( | ||
33 | descr | ||
34 | .scopes(self) | ||
35 | .find_all_refs(binding) | ||
36 | .into_iter() | ||
37 | .map(|ref_desc| (position.file_id, ref_desc.range)), | ||
38 | ); | ||
39 | |||
40 | return ret; | ||
41 | |||
42 | fn find_binding<'a>( | ||
43 | db: &db::RootDatabase, | ||
44 | source_file: &'a SourceFile, | ||
45 | position: FilePosition, | ||
46 | ) -> Option<(&'a ast::BindPat, hir::Function)> { | ||
47 | let syntax = source_file.syntax(); | ||
48 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | ||
49 | let descr = source_binder::function_from_child_node( | ||
50 | db, | ||
51 | position.file_id, | ||
52 | binding.syntax(), | ||
53 | )?; | ||
54 | return Some((binding, descr)); | ||
55 | }; | ||
56 | let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?; | ||
57 | let descr = | ||
58 | source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?; | ||
59 | let scope = descr.scopes(db); | ||
60 | let resolved = scope.resolve_local_name(name_ref)?; | ||
61 | let resolved = resolved.ptr().to_node(source_file); | ||
62 | let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?; | ||
63 | Some((binding, descr)) | ||
64 | } | ||
65 | } | ||
66 | |||
67 | pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { | 15 | pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> { |
68 | let syntax = self.parse(file_id); | 16 | let syntax = self.parse(file_id); |
69 | 17 | ||