diff options
Diffstat (limited to 'crates/ra_ide_api/src/search_scope.rs')
-rw-r--r-- | crates/ra_ide_api/src/search_scope.rs | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/crates/ra_ide_api/src/search_scope.rs b/crates/ra_ide_api/src/search_scope.rs index 9fcbdcc3a..1590a09c4 100644 --- a/crates/ra_ide_api/src/search_scope.rs +++ b/crates/ra_ide_api/src/search_scope.rs | |||
@@ -1,7 +1,5 @@ | |||
1 | use hir::{ | 1 | use hir::{DefWithBody, HasSource, ModuleSource, SourceAnalyzer}; |
2 | source_binder::ReferenceDescriptor, DefWithBody, HasSource, ModuleSource, SourceAnalyzer, | 2 | use ra_db::{FileId, FileRange, SourceDatabase}; |
3 | }; | ||
4 | use ra_db::{FileId, SourceDatabase}; | ||
5 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, TextRange, TextUnit}; | 3 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, TextRange, TextUnit}; |
6 | 4 | ||
7 | use crate::{ | 5 | use crate::{ |
@@ -13,11 +11,7 @@ pub(crate) struct SearchScope { | |||
13 | pub scope: Vec<(FileId, Option<TextRange>)>, | 11 | pub scope: Vec<(FileId, Option<TextRange>)>, |
14 | } | 12 | } |
15 | 13 | ||
16 | pub(crate) fn find_refs( | 14 | pub(crate) fn find_refs(db: &RootDatabase, def: Definition, name: String) -> Vec<FileRange> { |
17 | db: &RootDatabase, | ||
18 | def: Definition, | ||
19 | name: String, | ||
20 | ) -> Vec<ReferenceDescriptor> { | ||
21 | let pat = name.as_str(); | 15 | let pat = name.as_str(); |
22 | let scope = def.scope(db).scope; | 16 | let scope = def.scope(db).scope; |
23 | let mut refs = vec![]; | 17 | let mut refs = vec![]; |
@@ -40,20 +34,14 @@ pub(crate) fn find_refs( | |||
40 | for (idx, _) in text.match_indices(pat) { | 34 | for (idx, _) in text.match_indices(pat) { |
41 | let offset = TextUnit::from_usize(idx); | 35 | let offset = TextUnit::from_usize(idx); |
42 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, offset) { | 36 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, offset) { |
43 | let name_range = name_ref.syntax().text_range(); | 37 | let range = name_ref.syntax().text_range(); |
44 | 38 | ||
45 | if let Some(range) = text_range { | 39 | if let Some(text_range) = text_range { |
46 | if name_range.is_subrange(&range) && is_match(file_id, &name_ref) { | 40 | if range.is_subrange(&text_range) && is_match(file_id, &name_ref) { |
47 | refs.push(ReferenceDescriptor { | 41 | refs.push(FileRange { file_id, range }); |
48 | name: name_ref.text().to_string(), | ||
49 | range: name_ref.syntax().text_range(), | ||
50 | }); | ||
51 | } | 42 | } |
52 | } else if is_match(file_id, &name_ref) { | 43 | } else if is_match(file_id, &name_ref) { |
53 | refs.push(ReferenceDescriptor { | 44 | refs.push(FileRange { file_id, range }); |
54 | name: name_ref.text().to_string(), | ||
55 | range: name_ref.syntax().text_range(), | ||
56 | }); | ||
57 | } | 45 | } |
58 | } | 46 | } |
59 | } | 47 | } |
@@ -81,10 +69,10 @@ impl Definition { | |||
81 | let source_root = db.source_root(source_root_id); | 69 | let source_root = db.source_root(source_root_id); |
82 | let mut files = source_root.walk().map(|id| (id.into(), None)).collect::<Vec<_>>(); | 70 | let mut files = source_root.walk().map(|id| (id.into(), None)).collect::<Vec<_>>(); |
83 | 71 | ||
84 | if vis.syntax().text() == "pub(crate)" { | 72 | if vis.syntax().to_string().as_str() == "pub(crate)" { |
85 | return SearchScope { scope: files }; | 73 | return SearchScope { scope: files }; |
86 | } | 74 | } |
87 | if vis.syntax().text() == "pub" { | 75 | if vis.syntax().to_string().as_str() == "pub" { |
88 | let krate = self.container.krate(db).unwrap(); | 76 | let krate = self.container.krate(db).unwrap(); |
89 | let crate_graph = db.crate_graph(); | 77 | let crate_graph = db.crate_graph(); |
90 | 78 | ||