diff options
Diffstat (limited to 'crates/ra_ide_api/src/references.rs')
-rw-r--r-- | crates/ra_ide_api/src/references.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 9cb9433e7..1af7e8a9f 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs | |||
@@ -14,6 +14,7 @@ mod name_definition; | |||
14 | mod rename; | 14 | mod rename; |
15 | mod search_scope; | 15 | mod search_scope; |
16 | 16 | ||
17 | use hir::Source; | ||
17 | use once_cell::unsync::Lazy; | 18 | use once_cell::unsync::Lazy; |
18 | use ra_db::{SourceDatabase, SourceDatabaseExt}; | 19 | use ra_db::{SourceDatabase, SourceDatabaseExt}; |
19 | use ra_prof::profile; | 20 | use ra_prof::profile; |
@@ -114,7 +115,7 @@ fn find_name<'a>( | |||
114 | return Some(RangeInfo::new(range, (name.text().to_string(), def))); | 115 | return Some(RangeInfo::new(range, (name.text().to_string(), def))); |
115 | } | 116 | } |
116 | let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; | 117 | let name_ref = find_node_at_offset::<ast::NameRef>(&syntax, position.offset)?; |
117 | let def = classify_name_ref(db, position.file_id, &name_ref)?; | 118 | let def = classify_name_ref(db, Source::new(position.file_id.into(), &name_ref))?; |
118 | let range = name_ref.syntax().text_range(); | 119 | let range = name_ref.syntax().text_range(); |
119 | Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) | 120 | Some(RangeInfo::new(range, (name_ref.text().to_string(), def))) |
120 | } | 121 | } |
@@ -146,7 +147,7 @@ fn process_definition( | |||
146 | continue; | 147 | continue; |
147 | } | 148 | } |
148 | } | 149 | } |
149 | if let Some(d) = classify_name_ref(db, file_id, &name_ref) { | 150 | if let Some(d) = classify_name_ref(db, Source::new(file_id.into(), &name_ref)) { |
150 | if d == def { | 151 | if d == def { |
151 | refs.push(FileRange { file_id, range }); | 152 | refs.push(FileRange { file_id, range }); |
152 | } | 153 | } |
@@ -369,6 +370,21 @@ mod tests { | |||
369 | assert_eq!(refs.len(), 2); | 370 | assert_eq!(refs.len(), 2); |
370 | } | 371 | } |
371 | 372 | ||
373 | #[test] | ||
374 | fn test_find_all_refs_macro_def() { | ||
375 | let code = r#" | ||
376 | #[macro_export] | ||
377 | macro_rules! m1<|> { () => (()) } | ||
378 | |||
379 | fn foo() { | ||
380 | m1(); | ||
381 | m1(); | ||
382 | }"#; | ||
383 | |||
384 | let refs = get_all_refs(code); | ||
385 | assert_eq!(refs.len(), 3); | ||
386 | } | ||
387 | |||
372 | fn get_all_refs(text: &str) -> ReferenceSearchResult { | 388 | fn get_all_refs(text: &str) -> ReferenceSearchResult { |
373 | let (analysis, position) = single_file_with_position(text); | 389 | let (analysis, position) = single_file_with_position(text); |
374 | analysis.find_all_refs(position, None).unwrap().unwrap() | 390 | analysis.find_all_refs(position, None).unwrap().unwrap() |