diff options
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/search.rs | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 90e4e7b03..8f899ea56 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -4,10 +4,9 @@ | |||
4 | //! get a super-set of matches. Then, we we confirm each match using precise | 4 | //! get a super-set of matches. Then, we we confirm each match using precise |
5 | //! name resolution. | 5 | //! name resolution. |
6 | 6 | ||
7 | use std::{convert::TryInto, iter, mem}; | 7 | use std::{convert::TryInto, mem}; |
8 | 8 | ||
9 | use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt}; | 9 | use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt}; |
10 | use either::Either; | ||
11 | use hir::{ | 10 | use hir::{ |
12 | DefWithBody, HasAttrs, HasSource, InFile, ModuleDef, ModuleSource, Semantics, Visibility, | 11 | DefWithBody, HasAttrs, HasSource, InFile, ModuleDef, ModuleSource, Semantics, Visibility, |
13 | }; | 12 | }; |
@@ -370,37 +369,47 @@ impl<'a> FindUsages<'a> { | |||
370 | 369 | ||
371 | let tree = Lazy::new(|| sema.parse(file_id).syntax().clone()); | 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 { | 372 | let mut handle_match = |idx: usize| -> bool { |
374 | Either::Left(text.match_indices("Self")) | ||
375 | } else { | ||
376 | Either::Right(iter::empty()) | ||
377 | }); | ||
378 | |||
379 | for (idx, _) in matches { | ||
380 | let offset: TextSize = idx.try_into().unwrap(); | 373 | let offset: TextSize = idx.try_into().unwrap(); |
381 | if !search_range.contains_inclusive(offset) { | 374 | if !search_range.contains_inclusive(offset) { |
382 | continue; | 375 | return false; |
383 | } | 376 | } |
384 | 377 | ||
385 | if let Some(name) = sema.find_node_at_offset_with_descend(&tree, offset) { | 378 | if let Some(name) = sema.find_node_at_offset_with_descend(&tree, offset) { |
386 | match name { | 379 | match name { |
387 | ast::NameLike::NameRef(name_ref) => { | 380 | ast::NameLike::NameRef(name_ref) => { |
388 | if self.found_name_ref(&name_ref, sink) { | 381 | if self.found_name_ref(&name_ref, sink) { |
389 | return; | 382 | return true; |
390 | } | 383 | } |
391 | } | 384 | } |
392 | ast::NameLike::Name(name) => { | 385 | ast::NameLike::Name(name) => { |
393 | if self.found_name(&name, sink) { | 386 | if self.found_name(&name, sink) { |
394 | return; | 387 | return true; |
395 | } | 388 | } |
396 | } | 389 | } |
397 | ast::NameLike::Lifetime(lifetime) => { | 390 | ast::NameLike::Lifetime(lifetime) => { |
398 | if self.found_lifetime(&lifetime, sink) { | 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 | } |