refactor: reduce nesting
This commit is contained in:
parent
098d9d77b4
commit
60fa8fefa6
@ -460,7 +460,8 @@ fn scope_files<'a>(
|
|||||||
// `name` is stripped of raw ident prefix. See the comment on name retrieval above.
|
// `name` is stripped of raw ident prefix. See the comment on name retrieval above.
|
||||||
it.text().trim_start_matches("r#") == name
|
it.text().trim_start_matches("r#") == name
|
||||||
})
|
})
|
||||||
.map(|token| {
|
.into_iter()
|
||||||
|
.flat_map(|token| {
|
||||||
// FIXME: There should be optimization potential here
|
// FIXME: There should be optimization potential here
|
||||||
// Currently we try to descend everything we find which
|
// Currently we try to descend everything we find which
|
||||||
// means we call `Semantics::descend_into_macros` on
|
// means we call `Semantics::descend_into_macros` on
|
||||||
@ -476,30 +477,23 @@ fn scope_files<'a>(
|
|||||||
|
|
||||||
// Search for occurrences of the items name
|
// Search for occurrences of the items name
|
||||||
for offset in match_indices(&text, finder, search_range) {
|
for offset in match_indices(&text, finder, search_range) {
|
||||||
if let Some(iter) = find_nodes(name, &tree, offset) {
|
for name in find_nodes(name, &tree, offset).filter_map(ast::NameLike::cast) {
|
||||||
for name in iter.filter_map(ast::NameLike::cast) {
|
if match name {
|
||||||
if match name {
|
ast::NameLike::NameRef(name_ref) => self.found_name_ref(&name_ref, sink),
|
||||||
ast::NameLike::NameRef(name_ref) => {
|
ast::NameLike::Name(name) => self.found_name(&name, sink),
|
||||||
self.found_name_ref(&name_ref, sink)
|
ast::NameLike::Lifetime(lifetime) => self.found_lifetime(&lifetime, sink),
|
||||||
}
|
} {
|
||||||
ast::NameLike::Name(name) => self.found_name(&name, sink),
|
return;
|
||||||
ast::NameLike::Lifetime(lifetime) => {
|
|
||||||
self.found_lifetime(&lifetime, sink)
|
|
||||||
}
|
|
||||||
} {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Search for occurrences of the `Self` referring to our type
|
// Search for occurrences of the `Self` referring to our type
|
||||||
if let Some((self_ty, finder)) = &include_self_kw_refs {
|
if let Some((self_ty, finder)) = &include_self_kw_refs {
|
||||||
for offset in match_indices(&text, finder, search_range) {
|
for offset in match_indices(&text, finder, search_range) {
|
||||||
if let Some(iter) = find_nodes("Self", &tree, offset) {
|
for name_ref in find_nodes("Self", &tree, offset).filter_map(ast::NameRef::cast)
|
||||||
for name_ref in iter.filter_map(ast::NameRef::cast) {
|
{
|
||||||
if self.found_self_ty_name_ref(self_ty, &name_ref, sink) {
|
if self.found_self_ty_name_ref(self_ty, &name_ref, sink) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -518,21 +512,21 @@ fn scope_files<'a>(
|
|||||||
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
|
let tree = Lazy::new(move || sema.parse(file_id).syntax().clone());
|
||||||
|
|
||||||
for offset in match_indices(&text, finder, search_range) {
|
for offset in match_indices(&text, finder, search_range) {
|
||||||
if let Some(iter) = find_nodes("super", &tree, offset) {
|
for name_ref in
|
||||||
for name_ref in iter.filter_map(ast::NameRef::cast) {
|
find_nodes("super", &tree, offset).filter_map(ast::NameRef::cast)
|
||||||
if self.found_name_ref(&name_ref, sink) {
|
{
|
||||||
return;
|
if self.found_name_ref(&name_ref, sink) {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(finder) = &is_crate_root {
|
if let Some(finder) = &is_crate_root {
|
||||||
for offset in match_indices(&text, finder, search_range) {
|
for offset in match_indices(&text, finder, search_range) {
|
||||||
if let Some(iter) = find_nodes("crate", &tree, offset) {
|
for name_ref in
|
||||||
for name_ref in iter.filter_map(ast::NameRef::cast) {
|
find_nodes("crate", &tree, offset).filter_map(ast::NameRef::cast)
|
||||||
if self.found_name_ref(&name_ref, sink) {
|
{
|
||||||
return;
|
if self.found_name_ref(&name_ref, sink) {
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,11 +565,10 @@ fn scope_files<'a>(
|
|||||||
let finder = &Finder::new("self");
|
let finder = &Finder::new("self");
|
||||||
|
|
||||||
for offset in match_indices(&text, finder, search_range) {
|
for offset in match_indices(&text, finder, search_range) {
|
||||||
if let Some(iter) = find_nodes("self", &tree, offset) {
|
for name_ref in find_nodes("self", &tree, offset).filter_map(ast::NameRef::cast)
|
||||||
for name_ref in iter.filter_map(ast::NameRef::cast) {
|
{
|
||||||
if self.found_self_module_name_ref(&name_ref, sink) {
|
if self.found_self_module_name_ref(&name_ref, sink) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user