aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/references.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/references.rs')
-rw-r--r--crates/ra_ide/src/references.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 2c753dade..5e2fe1905 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -14,7 +14,7 @@ mod name_definition;
14mod rename; 14mod rename;
15mod search_scope; 15mod search_scope;
16 16
17use hir::InFile; 17use hir::{InFile, SourceBinder};
18use once_cell::unsync::Lazy; 18use once_cell::unsync::Lazy;
19use ra_db::{SourceDatabase, SourceDatabaseExt}; 19use ra_db::{SourceDatabase, SourceDatabaseExt};
20use ra_prof::profile; 20use ra_prof::profile;
@@ -171,13 +171,14 @@ fn find_name(
171 syntax: &SyntaxNode, 171 syntax: &SyntaxNode,
172 position: FilePosition, 172 position: FilePosition,
173) -> Option<RangeInfo<(String, NameDefinition)>> { 173) -> Option<RangeInfo<(String, NameDefinition)>> {
174 let mut sb = SourceBinder::new(db);
174 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) { 175 if let Some(name) = find_node_at_offset::<ast::Name>(&syntax, position.offset) {
175 let def = classify_name(db, InFile::new(position.file_id.into(), &name))?; 176 let def = classify_name(&mut sb, InFile::new(position.file_id.into(), &name))?;
176 let range = name.syntax().text_range(); 177 let range = name.syntax().text_range();
177 return Some(RangeInfo::new(range, (name.text().to_string(), def))); 178 return Some(RangeInfo::new(range, (name.text().to_string(), def)));
178 } 179 }
179 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; 180 let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?;
180 let def = classify_name_ref(db, InFile::new(position.file_id.into(), &name_ref))?; 181 let def = classify_name_ref(&mut sb, InFile::new(position.file_id.into(), &name_ref))?;
181 let range = name_ref.syntax().text_range(); 182 let range = name_ref.syntax().text_range();
182 Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) 183 Some(RangeInfo::new(range, (name_ref.text().to_string(), def)))
183} 184}
@@ -195,7 +196,9 @@ fn process_definition(
195 196
196 for (file_id, search_range) in scope { 197 for (file_id, search_range) in scope {
197 let text = db.file_text(file_id); 198 let text = db.file_text(file_id);
199
198 let parse = Lazy::new(|| SourceFile::parse(&text)); 200 let parse = Lazy::new(|| SourceFile::parse(&text));
201 let mut sb = Lazy::new(|| SourceBinder::new(db));
199 202
200 for (idx, _) in text.match_indices(pat) { 203 for (idx, _) in text.match_indices(pat) {
201 let offset = TextUnit::from_usize(idx); 204 let offset = TextUnit::from_usize(idx);
@@ -209,7 +212,11 @@ fn process_definition(
209 continue; 212 continue;
210 } 213 }
211 } 214 }
212 if let Some(d) = classify_name_ref(db, InFile::new(file_id.into(), &name_ref)) { 215 // FIXME: reuse sb
216 // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098
217
218 if let Some(d) = classify_name_ref(&mut sb, InFile::new(file_id.into(), &name_ref))
219 {
213 if d == def { 220 if d == def {
214 let kind = if name_ref 221 let kind = if name_ref
215 .syntax() 222 .syntax()
@@ -309,7 +316,7 @@ mod tests {
309 } 316 }
310 impl Foo { 317 impl Foo {
311 fn f() -> i32 { 42 } 318 fn f() -> i32 { 42 }
312 } 319 }
313 fn main() { 320 fn main() {
314 let f: Foo; 321 let f: Foo;
315 f = Foo {a: Foo::f()}; 322 f = Foo {a: Foo::f()};
@@ -319,7 +326,7 @@ mod tests {
319 check_result( 326 check_result(
320 refs, 327 refs,
321 "Foo STRUCT_DEF FileId(1) [5; 39) [12; 15) Other", 328 "Foo STRUCT_DEF FileId(1) [5; 39) [12; 15) Other",
322 &["FileId(1) [142; 145) StructLiteral"], 329 &["FileId(1) [138; 141) StructLiteral"],
323 ); 330 );
324 } 331 }
325 332