diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_ide/src/references.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_ide/src/references.rs')
-rw-r--r-- | crates/ra_ide/src/references.rs | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 3433fdae3..519e4bf1a 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -74,8 +74,8 @@ impl IntoIterator for ReferenceSearchResult { | |||
74 | let mut v = Vec::with_capacity(self.len()); | 74 | let mut v = Vec::with_capacity(self.len()); |
75 | v.push(Reference { | 75 | v.push(Reference { |
76 | file_range: FileRange { | 76 | file_range: FileRange { |
77 | file_id: self.declaration.nav.file_id(), | 77 | file_id: self.declaration.nav.file_id, |
78 | range: self.declaration.nav.range(), | 78 | range: self.declaration.nav.focus_or_full_range(), |
79 | }, | 79 | }, |
80 | kind: self.declaration.kind, | 80 | kind: self.declaration.kind, |
81 | access: self.declaration.access, | 81 | access: self.declaration.access, |
@@ -86,12 +86,11 @@ impl IntoIterator for ReferenceSearchResult { | |||
86 | } | 86 | } |
87 | 87 | ||
88 | pub(crate) fn find_all_refs( | 88 | pub(crate) fn find_all_refs( |
89 | db: &RootDatabase, | 89 | sema: &Semantics<RootDatabase>, |
90 | position: FilePosition, | 90 | position: FilePosition, |
91 | search_scope: Option<SearchScope>, | 91 | search_scope: Option<SearchScope>, |
92 | ) -> Option<RangeInfo<ReferenceSearchResult>> { | 92 | ) -> Option<RangeInfo<ReferenceSearchResult>> { |
93 | let _p = profile("find_all_refs"); | 93 | let _p = profile("find_all_refs"); |
94 | let sema = Semantics::new(db); | ||
95 | let syntax = sema.parse(position.file_id).syntax().clone(); | 94 | let syntax = sema.parse(position.file_id).syntax().clone(); |
96 | 95 | ||
97 | let (opt_name, search_kind) = if let Some(name) = | 96 | let (opt_name, search_kind) = if let Some(name) = |
@@ -108,15 +107,15 @@ pub(crate) fn find_all_refs( | |||
108 | let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?; | 107 | let RangeInfo { range, info: def } = find_name(&sema, &syntax, position, opt_name)?; |
109 | 108 | ||
110 | let references = def | 109 | let references = def |
111 | .find_usages(db, search_scope) | 110 | .find_usages(sema, search_scope) |
112 | .into_iter() | 111 | .into_iter() |
113 | .filter(|r| search_kind == ReferenceKind::Other || search_kind == r.kind) | 112 | .filter(|r| search_kind == ReferenceKind::Other || search_kind == r.kind) |
114 | .collect(); | 113 | .collect(); |
115 | 114 | ||
116 | let decl_range = def.try_to_nav(db)?.range(); | 115 | let decl_range = def.try_to_nav(sema.db)?.focus_or_full_range(); |
117 | 116 | ||
118 | let declaration = Declaration { | 117 | let declaration = Declaration { |
119 | nav: def.try_to_nav(db)?, | 118 | nav: def.try_to_nav(sema.db)?, |
120 | kind: ReferenceKind::Other, | 119 | kind: ReferenceKind::Other, |
121 | access: decl_access(&def, &syntax, decl_range), | 120 | access: decl_access(&def, &syntax, decl_range), |
122 | }; | 121 | }; |
@@ -173,16 +172,16 @@ fn get_struct_def_name_for_struct_literal_search( | |||
173 | if let Some(name) = | 172 | if let Some(name) = |
174 | sema.find_node_at_offset_with_descend::<ast::Name>(&syntax, left.text_range().start()) | 173 | sema.find_node_at_offset_with_descend::<ast::Name>(&syntax, left.text_range().start()) |
175 | { | 174 | { |
176 | return name.syntax().ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); | 175 | return name.syntax().ancestors().find_map(ast::Struct::cast).and_then(|l| l.name()); |
177 | } | 176 | } |
178 | if sema | 177 | if sema |
179 | .find_node_at_offset_with_descend::<ast::TypeParamList>( | 178 | .find_node_at_offset_with_descend::<ast::GenericParamList>( |
180 | &syntax, | 179 | &syntax, |
181 | left.text_range().start(), | 180 | left.text_range().start(), |
182 | ) | 181 | ) |
183 | .is_some() | 182 | .is_some() |
184 | { | 183 | { |
185 | return left.ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); | 184 | return left.ancestors().find_map(ast::Struct::cast).and_then(|l| l.name()); |
186 | } | 185 | } |
187 | } | 186 | } |
188 | None | 187 | None |
@@ -213,7 +212,7 @@ fn main() { | |||
213 | ); | 212 | ); |
214 | check_result( | 213 | check_result( |
215 | refs, | 214 | refs, |
216 | "Foo STRUCT_DEF FileId(1) 0..26 7..10 Other", | 215 | "Foo STRUCT FileId(1) 0..26 7..10 Other", |
217 | &["FileId(1) 101..104 StructLiteral"], | 216 | &["FileId(1) 101..104 StructLiteral"], |
218 | ); | 217 | ); |
219 | } | 218 | } |
@@ -231,7 +230,7 @@ struct Foo<|> {} | |||
231 | ); | 230 | ); |
232 | check_result( | 231 | check_result( |
233 | refs, | 232 | refs, |
234 | "Foo STRUCT_DEF FileId(1) 0..13 7..10 Other", | 233 | "Foo STRUCT FileId(1) 0..13 7..10 Other", |
235 | &["FileId(1) 41..44 Other", "FileId(1) 54..57 StructLiteral"], | 234 | &["FileId(1) 41..44 Other", "FileId(1) 54..57 StructLiteral"], |
236 | ); | 235 | ); |
237 | } | 236 | } |
@@ -249,7 +248,7 @@ struct Foo<T> <|>{} | |||
249 | ); | 248 | ); |
250 | check_result( | 249 | check_result( |
251 | refs, | 250 | refs, |
252 | "Foo STRUCT_DEF FileId(1) 0..16 7..10 Other", | 251 | "Foo STRUCT FileId(1) 0..16 7..10 Other", |
253 | &["FileId(1) 64..67 StructLiteral"], | 252 | &["FileId(1) 64..67 StructLiteral"], |
254 | ); | 253 | ); |
255 | } | 254 | } |
@@ -268,7 +267,7 @@ fn main() { | |||
268 | ); | 267 | ); |
269 | check_result( | 268 | check_result( |
270 | refs, | 269 | refs, |
271 | "Foo STRUCT_DEF FileId(1) 0..16 7..10 Other", | 270 | "Foo STRUCT FileId(1) 0..16 7..10 Other", |
272 | &["FileId(1) 54..57 StructLiteral"], | 271 | &["FileId(1) 54..57 StructLiteral"], |
273 | ); | 272 | ); |
274 | } | 273 | } |
@@ -362,7 +361,7 @@ fn main(s: Foo) { | |||
362 | ); | 361 | ); |
363 | check_result( | 362 | check_result( |
364 | refs, | 363 | refs, |
365 | "spam RECORD_FIELD_DEF FileId(1) 17..30 21..25 Other", | 364 | "spam RECORD_FIELD FileId(1) 17..30 21..25 Other", |
366 | &["FileId(1) 67..71 Other Read"], | 365 | &["FileId(1) 67..71 Other Read"], |
367 | ); | 366 | ); |
368 | } | 367 | } |
@@ -377,7 +376,7 @@ impl Foo { | |||
377 | } | 376 | } |
378 | "#, | 377 | "#, |
379 | ); | 378 | ); |
380 | check_result(refs, "f FN_DEF FileId(1) 27..43 30..31 Other", &[]); | 379 | check_result(refs, "f FN FileId(1) 27..43 30..31 Other", &[]); |
381 | } | 380 | } |
382 | 381 | ||
383 | #[test] | 382 | #[test] |
@@ -391,7 +390,7 @@ enum Foo { | |||
391 | } | 390 | } |
392 | "#, | 391 | "#, |
393 | ); | 392 | ); |
394 | check_result(refs, "B ENUM_VARIANT FileId(1) 22..23 22..23 Other", &[]); | 393 | check_result(refs, "B VARIANT FileId(1) 22..23 22..23 Other", &[]); |
395 | } | 394 | } |
396 | 395 | ||
397 | #[test] | 396 | #[test] |
@@ -432,7 +431,7 @@ fn f() { | |||
432 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); | 431 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); |
433 | check_result( | 432 | check_result( |
434 | refs, | 433 | refs, |
435 | "Foo STRUCT_DEF FileId(2) 17..51 28..31 Other", | 434 | "Foo STRUCT FileId(2) 17..51 28..31 Other", |
436 | &["FileId(1) 53..56 StructLiteral", "FileId(3) 79..82 StructLiteral"], | 435 | &["FileId(1) 53..56 StructLiteral", "FileId(3) 79..82 StructLiteral"], |
437 | ); | 436 | ); |
438 | } | 437 | } |
@@ -487,7 +486,7 @@ pub(super) struct Foo<|> { | |||
487 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); | 486 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); |
488 | check_result( | 487 | check_result( |
489 | refs, | 488 | refs, |
490 | "Foo STRUCT_DEF FileId(3) 0..41 18..21 Other", | 489 | "Foo STRUCT FileId(3) 0..41 18..21 Other", |
491 | &["FileId(2) 20..23 Other", "FileId(2) 47..50 StructLiteral"], | 490 | &["FileId(2) 20..23 Other", "FileId(2) 47..50 StructLiteral"], |
492 | ); | 491 | ); |
493 | } | 492 | } |
@@ -515,7 +514,7 @@ pub(super) struct Foo<|> { | |||
515 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); | 514 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); |
516 | check_result( | 515 | check_result( |
517 | refs, | 516 | refs, |
518 | "quux FN_DEF FileId(1) 19..35 26..30 Other", | 517 | "quux FN FileId(1) 19..35 26..30 Other", |
519 | &["FileId(2) 16..20 StructLiteral", "FileId(3) 16..20 StructLiteral"], | 518 | &["FileId(2) 16..20 StructLiteral", "FileId(3) 16..20 StructLiteral"], |
520 | ); | 519 | ); |
521 | 520 | ||
@@ -523,7 +522,7 @@ pub(super) struct Foo<|> { | |||
523 | analysis.find_all_refs(pos, Some(SearchScope::single_file(bar))).unwrap().unwrap(); | 522 | analysis.find_all_refs(pos, Some(SearchScope::single_file(bar))).unwrap().unwrap(); |
524 | check_result( | 523 | check_result( |
525 | refs, | 524 | refs, |
526 | "quux FN_DEF FileId(1) 19..35 26..30 Other", | 525 | "quux FN FileId(1) 19..35 26..30 Other", |
527 | &["FileId(3) 16..20 StructLiteral"], | 526 | &["FileId(3) 16..20 StructLiteral"], |
528 | ); | 527 | ); |
529 | } | 528 | } |
@@ -581,7 +580,7 @@ fn foo() { | |||
581 | ); | 580 | ); |
582 | check_result( | 581 | check_result( |
583 | refs, | 582 | refs, |
584 | "f RECORD_FIELD_DEF FileId(1) 15..21 15..16 Other", | 583 | "f RECORD_FIELD FileId(1) 15..21 15..16 Other", |
585 | &["FileId(1) 55..56 Other Read", "FileId(1) 68..69 Other Write"], | 584 | &["FileId(1) 55..56 Other Read", "FileId(1) 68..69 Other Write"], |
586 | ); | 585 | ); |
587 | } | 586 | } |
@@ -620,7 +619,7 @@ fn main() { | |||
620 | ); | 619 | ); |
621 | check_result( | 620 | check_result( |
622 | refs, | 621 | refs, |
623 | "new FN_DEF FileId(1) 54..101 61..64 Other", | 622 | "new FN FileId(1) 54..101 61..64 Other", |
624 | &["FileId(1) 146..149 StructLiteral"], | 623 | &["FileId(1) 146..149 StructLiteral"], |
625 | ); | 624 | ); |
626 | } | 625 | } |
@@ -647,7 +646,7 @@ fn main() { | |||
647 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); | 646 | let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); |
648 | check_result( | 647 | check_result( |
649 | refs, | 648 | refs, |
650 | "f FN_DEF FileId(1) 26..35 29..30 Other", | 649 | "f FN FileId(1) 26..35 29..30 Other", |
651 | &["FileId(2) 11..12 Other", "FileId(2) 28..29 StructLiteral"], | 650 | &["FileId(2) 11..12 Other", "FileId(2) 28..29 StructLiteral"], |
652 | ); | 651 | ); |
653 | } | 652 | } |