|
4 | 4 | //! get a super-set of matches. Then, we we confirm each match using precise
|
5 | 5 | //! name resolution.
|
6 | 6 |
|
7 |
| -use std::{convert::TryInto, iter, mem}; |
| 7 | +use std::{convert::TryInto, mem}; |
8 | 8 |
|
9 | 9 | use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt};
|
10 |
| -use either::Either; |
11 | 10 | use hir::{
|
12 | 11 | DefWithBody, HasAttrs, HasSource, InFile, ModuleDef, ModuleSource, Semantics, Visibility,
|
13 | 12 | };
|
@@ -370,37 +369,47 @@ impl<'a> FindUsages<'a> {
|
370 | 369 |
|
371 | 370 | let tree = Lazy::new(|| sema.parse(file_id).syntax().clone());
|
372 | 371 |
|
373 |
| - let matches = text.match_indices(pat).chain(if search_for_self { |
374 |
| - Either::Left(text.match_indices("Self")) |
375 |
| - } else { |
376 |
| - Either::Right(iter::empty()) |
377 |
| - }); |
378 |
| - |
379 |
| - for (idx, _) in matches { |
| 372 | + let mut handle_match = |idx: usize| -> bool { |
380 | 373 | let offset: TextSize = idx.try_into().unwrap();
|
381 | 374 | if !search_range.contains_inclusive(offset) {
|
382 |
| - continue; |
| 375 | + return false; |
383 | 376 | }
|
384 | 377 |
|
385 | 378 | if let Some(name) = sema.find_node_at_offset_with_descend(&tree, offset) {
|
386 | 379 | match name {
|
387 | 380 | ast::NameLike::NameRef(name_ref) => {
|
388 | 381 | if self.found_name_ref(&name_ref, sink) {
|
389 |
| - return; |
| 382 | + return true; |
390 | 383 | }
|
391 | 384 | }
|
392 | 385 | ast::NameLike::Name(name) => {
|
393 | 386 | if self.found_name(&name, sink) {
|
394 |
| - return; |
| 387 | + return true; |
395 | 388 | }
|
396 | 389 | }
|
397 | 390 | ast::NameLike::Lifetime(lifetime) => {
|
398 | 391 | if self.found_lifetime(&lifetime, sink) {
|
399 |
| - return; |
| 392 | + return true; |
400 | 393 | }
|
401 | 394 | }
|
402 | 395 | }
|
403 | 396 | }
|
| 397 | + |
| 398 | + return false; |
| 399 | + }; |
| 400 | + |
| 401 | + for (idx, _) in text.match_indices(pat) { |
| 402 | + if handle_match(idx) { |
| 403 | + return; |
| 404 | + } |
| 405 | + } |
| 406 | + |
| 407 | + if search_for_self { |
| 408 | + for (idx, _) in text.match_indices("Self") { |
| 409 | + if handle_match(idx) { |
| 410 | + return; |
| 411 | + } |
| 412 | + } |
404 | 413 | }
|
405 | 414 | }
|
406 | 415 | }
|
|
0 commit comments