mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-31 23:38:45 +00:00
Retain imports on find-all-references
This commit is contained in:
parent
8ddb8b7e8e
commit
29729abc3c
1 changed files with 28 additions and 0 deletions
|
@ -79,6 +79,8 @@ pub(crate) fn find_all_refs(
|
||||||
retain_adt_literal_usages(&mut usages, def, sema);
|
retain_adt_literal_usages(&mut usages, def, sema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retain_import_usages(&mut usages, sema);
|
||||||
|
|
||||||
let references = usages
|
let references = usages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(file_id, refs)| {
|
.map(|(file_id, refs)| {
|
||||||
|
@ -112,6 +114,32 @@ pub(crate) fn find_all_refs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn retain_import_usages(usages: &mut UsageSearchResult, sema: &Semantics<'_, RootDatabase>) {
|
||||||
|
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) => {
|
||||||
|
if matches!(x.kind(), USE) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
syntax::NodeOrToken::Token(_) => true,
|
||||||
|
};
|
||||||
|
res
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn find_defs<'a>(
|
pub(crate) fn find_defs<'a>(
|
||||||
sema: &'a Semantics<'_, RootDatabase>,
|
sema: &'a Semantics<'_, RootDatabase>,
|
||||||
syntax: &SyntaxNode,
|
syntax: &SyntaxNode,
|
||||||
|
|
Loading…
Reference in a new issue