Unnamed repository; edit this file 'description' to name the repository.
Remove unnecessary special local handling in search
Lukas Wirth 2023-03-09
parent 38e9a11 · commit e158dc7
-rw-r--r--crates/ide-db/src/search.rs43
1 files changed, 5 insertions, 38 deletions
diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs
index 6298ea1927..77d694b57f 100644
--- a/crates/ide-db/src/search.rs
+++ b/crates/ide-db/src/search.rs
@@ -319,10 +319,6 @@ impl Definition {
sema,
scope: None,
include_self_kw_refs: None,
- local_repr: match self {
- Definition::Local(local) => Some(local),
- _ => None,
- },
search_self_mod: false,
}
}
@@ -337,9 +333,6 @@ pub struct FindUsages<'a> {
assoc_item_container: Option<hir::AssocItemContainer>,
/// whether to search for the `Self` type of the definition
include_self_kw_refs: Option<hir::Type>,
- /// the local representative for the local definition we are searching for
- /// (this is required for finding all local declarations in a or-pattern)
- local_repr: Option<hir::Local>,
/// whether to search for the `self` module
search_self_mod: bool,
}
@@ -644,19 +637,6 @@ impl<'a> FindUsages<'a> {
sink: &mut dyn FnMut(FileId, FileReference) -> bool,
) -> bool {
match NameRefClass::classify(self.sema, name_ref) {
- Some(NameRefClass::Definition(def @ Definition::Local(local)))
- if matches!(
- self.local_repr, Some(repr) if repr == local
- ) =>
- {
- let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
- let reference = FileReference {
- range,
- name: ast::NameLike::NameRef(name_ref.clone()),
- category: ReferenceCategory::new(&def, name_ref),
- };
- sink(file_id, reference)
- }
Some(NameRefClass::Definition(def))
if self.def == def
// is our def a trait assoc item? then we want to find all assoc items from trait impls of our trait
@@ -701,14 +681,16 @@ impl<'a> FindUsages<'a> {
}
}
Some(NameRefClass::FieldShorthand { local_ref: local, field_ref: field }) => {
- let field = Definition::Field(field);
let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax());
+
+ let field = Definition::Field(field);
+ let local = Definition::Local(local);
let access = match self.def {
Definition::Field(_) if field == self.def => {
ReferenceCategory::new(&field, name_ref)
}
- Definition::Local(_) if matches!(self.local_repr, Some(repr) if repr == local) => {
- ReferenceCategory::new(&Definition::Local(local), name_ref)
+ Definition::Local(_) if local == self.def => {
+ ReferenceCategory::new(&local, name_ref)
}
_ => return false,
};
@@ -752,21 +734,6 @@ impl<'a> FindUsages<'a> {
};
sink(file_id, reference)
}
- Some(NameClass::Definition(def @ Definition::Local(local))) if def != self.def => {
- if matches!(
- self.local_repr,
- Some(repr) if local == repr
- ) {
- let FileRange { file_id, range } = self.sema.original_range(name.syntax());
- let reference = FileReference {
- range,
- name: ast::NameLike::Name(name.clone()),
- category: None,
- };
- return sink(file_id, reference);
- }
- false
- }
Some(NameClass::Definition(def)) if def != self.def => {
match (&self.assoc_item_container, self.def) {
// for type aliases we always want to reference the trait def and all the trait impl counterparts