Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter imports on find-all-references #13186

Merged
merged 12 commits into from
Sep 12, 2022
28 changes: 28 additions & 0 deletions crates/ide/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub(crate) fn find_all_refs(
retain_adt_literal_usages(&mut usages, def, sema);
}

retain_import_usages(&mut usages, sema);

let references = usages
.into_iter()
.map(|(file_id, refs)| {
Expand Down Expand Up @@ -112,6 +114,32 @@ pub(crate) fn find_all_refs(
}
}

fn retain_import_usages(usages: &mut UsageSearchResult, sema: &Semantics<'_, RootDatabase>) {
enomado marked this conversation as resolved.
Show resolved Hide resolved
for (file_id, refs) in &mut usages.references {
refs.retain(|x| {
let file_sema = sema.parse(file_id.clone()).syntax().clone();

let maybe_node = file_sema.child_or_token_at_range(x.range.clone());

if let Some(node) = maybe_node {
let res = match node {
syntax::NodeOrToken::Node(x) => !matches!(x.kind(), USE),
enomado marked this conversation as resolved.
Show resolved Hide resolved
if matches!(x.kind(), USE) {
false
} else {
true
}
}
syntax::NodeOrToken::Token(_) => true,
};
res
} else {
true
}
});
}
}

pub(crate) fn find_defs<'a>(
sema: &'a Semantics<'_, RootDatabase>,
syntax: &SyntaxNode,
Expand Down