diff options
Diffstat (limited to 'crates/ra_ide_api/src/references.rs')
-rw-r--r-- | crates/ra_ide_api/src/references.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 3761fd6e7..3d282d48a 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -5,6 +5,7 @@ mod name_definition; | |||
5 | mod rename; | 5 | mod rename; |
6 | mod search_scope; | 6 | mod search_scope; |
7 | 7 | ||
8 | use once_cell::unsync::Lazy; | ||
8 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 9 | use ra_db::{SourceDatabase, SourceDatabaseExt}; |
9 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode, TextUnit}; | 10 | use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode, TextUnit}; |
10 | 11 | ||
@@ -61,7 +62,7 @@ pub(crate) fn find_all_refs( | |||
61 | let syntax = parse.tree().syntax().clone(); | 62 | let syntax = parse.tree().syntax().clone(); |
62 | let RangeInfo { range, info: (name, def) } = find_name(db, &syntax, position)?; | 63 | let RangeInfo { range, info: (name, def) } = find_name(db, &syntax, position)?; |
63 | 64 | ||
64 | let declaration = match def.item { | 65 | let declaration = match def.kind { |
65 | NameKind::Macro(mac) => NavigationTarget::from_macro_def(db, mac), | 66 | NameKind::Macro(mac) => NavigationTarget::from_macro_def(db, mac), |
66 | NameKind::Field(field) => NavigationTarget::from_field(db, field), | 67 | NameKind::Field(field) => NavigationTarget::from_field(db, field), |
67 | NameKind::AssocItem(assoc) => NavigationTarget::from_assoc_item(db, assoc), | 68 | NameKind::AssocItem(assoc) => NavigationTarget::from_assoc_item(db, assoc), |
@@ -98,7 +99,7 @@ fn find_name<'a>( | |||
98 | 99 | ||
99 | fn process_definition(db: &RootDatabase, def: NameDefinition, name: String) -> Vec<FileRange> { | 100 | fn process_definition(db: &RootDatabase, def: NameDefinition, name: String) -> Vec<FileRange> { |
100 | let pat = name.as_str(); | 101 | let pat = name.as_str(); |
101 | let scope = def.scope(db).scope; | 102 | let scope = def.scope(db).files; |
102 | let mut refs = vec![]; | 103 | let mut refs = vec![]; |
103 | 104 | ||
104 | let is_match = |file_id: FileId, name_ref: &ast::NameRef| -> bool { | 105 | let is_match = |file_id: FileId, name_ref: &ast::NameRef| -> bool { |
@@ -112,12 +113,14 @@ fn process_definition(db: &RootDatabase, def: NameDefinition, name: String) -> V | |||
112 | 113 | ||
113 | for (file_id, text_range) in scope { | 114 | for (file_id, text_range) in scope { |
114 | let text = db.file_text(file_id); | 115 | let text = db.file_text(file_id); |
115 | let parse = SourceFile::parse(&text); | 116 | let parse = Lazy::new(|| SourceFile::parse(&text)); |
116 | let syntax = parse.tree().syntax().clone(); | ||
117 | 117 | ||
118 | for (idx, _) in text.match_indices(pat) { | 118 | for (idx, _) in text.match_indices(pat) { |
119 | let offset = TextUnit::from_usize(idx); | 119 | let offset = TextUnit::from_usize(idx); |
120 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(&syntax, offset) { | 120 | |
121 | if let Some(name_ref) = | ||
122 | find_node_at_offset::<ast::NameRef>(parse.tree().syntax(), offset) | ||
123 | { | ||
121 | let range = name_ref.syntax().text_range(); | 124 | let range = name_ref.syntax().text_range(); |
122 | 125 | ||
123 | if let Some(text_range) = text_range { | 126 | if let Some(text_range) = text_range { |