Rename FileReferences -> UsageSearchResult
This commit is contained in:
parent
2c1777a2e2
commit
aff9102afb
@ -15,7 +15,7 @@
|
||||
use ide_db::{
|
||||
base_db::FileId,
|
||||
defs::{Definition, NameClass, NameRefClass},
|
||||
search::{FileReference, FileReferences, ReferenceAccess, ReferenceKind, SearchScope},
|
||||
search::{FileReference, ReferenceAccess, ReferenceKind, SearchScope, UsageSearchResult},
|
||||
RootDatabase,
|
||||
};
|
||||
use syntax::{
|
||||
@ -29,7 +29,7 @@
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ReferenceSearchResult {
|
||||
declaration: Declaration,
|
||||
references: FileReferences,
|
||||
references: UsageSearchResult,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -48,11 +48,11 @@ pub fn decl_target(&self) -> &NavigationTarget {
|
||||
&self.declaration.nav
|
||||
}
|
||||
|
||||
pub fn references(&self) -> &FileReferences {
|
||||
pub fn references(&self) -> &UsageSearchResult {
|
||||
&self.references
|
||||
}
|
||||
|
||||
pub fn references_with_declaration(mut self) -> FileReferences {
|
||||
pub fn references_with_declaration(mut self) -> UsageSearchResult {
|
||||
let decl_ref = FileReference {
|
||||
range: self.declaration.nav.focus_or_full_range(),
|
||||
kind: self.declaration.kind,
|
||||
@ -315,7 +315,7 @@ fn try_find_self_references(
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let mut references = FileReferences::default();
|
||||
let mut references = UsageSearchResult::default();
|
||||
references.references.insert(file_id, refs);
|
||||
|
||||
Some(RangeInfo::new(
|
||||
|
@ -19,11 +19,11 @@
|
||||
};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct FileReferences {
|
||||
pub struct UsageSearchResult {
|
||||
pub references: FxHashMap<FileId, Vec<FileReference>>,
|
||||
}
|
||||
|
||||
impl FileReferences {
|
||||
impl UsageSearchResult {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.references.is_empty()
|
||||
}
|
||||
@ -43,7 +43,7 @@ pub fn file_ranges(&self) -> impl Iterator<Item = FileRange> + '_ {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for FileReferences {
|
||||
impl IntoIterator for UsageSearchResult {
|
||||
type Item = (FileId, Vec<FileReference>);
|
||||
type IntoIter = <FxHashMap<FileId, Vec<FileReference>> as IntoIterator>::IntoIter;
|
||||
|
||||
@ -293,9 +293,8 @@ pub fn at_least_one(self) -> bool {
|
||||
found
|
||||
}
|
||||
|
||||
/// The [`FileReferences`] returned always have unique [`FileId`]s.
|
||||
pub fn all(self) -> FileReferences {
|
||||
let mut res = FileReferences::default();
|
||||
pub fn all(self) -> UsageSearchResult {
|
||||
let mut res = UsageSearchResult::default();
|
||||
self.search(&mut |file_id, reference| {
|
||||
res.references.entry(file_id).or_default().push(reference);
|
||||
false
|
||||
|
@ -8,7 +8,7 @@
|
||||
use ide_db::{
|
||||
base_db::{FileId, FileRange},
|
||||
defs::Definition,
|
||||
search::{FileReferences, SearchScope},
|
||||
search::{SearchScope, UsageSearchResult},
|
||||
};
|
||||
use rustc_hash::FxHashSet;
|
||||
use syntax::{ast, AstNode, SyntaxKind, SyntaxNode};
|
||||
@ -20,7 +20,7 @@
|
||||
/// them more than once.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct UsageCache {
|
||||
usages: Vec<(Definition, FileReferences)>,
|
||||
usages: Vec<(Definition, UsageSearchResult)>,
|
||||
}
|
||||
|
||||
impl<'db> MatchFinder<'db> {
|
||||
@ -108,7 +108,7 @@ fn find_usages<'a>(
|
||||
&self,
|
||||
usage_cache: &'a mut UsageCache,
|
||||
definition: Definition,
|
||||
) -> &'a FileReferences {
|
||||
) -> &'a UsageSearchResult {
|
||||
// Logically if a lookup succeeds we should just return it. Unfortunately returning it would
|
||||
// extend the lifetime of the borrow, then we wouldn't be able to do the insertion on a
|
||||
// cache miss. This is a limitation of NLL and is fixed with Polonius. For now we do two
|
||||
@ -250,7 +250,7 @@ fn is_search_permitted(node: &SyntaxNode) -> bool {
|
||||
}
|
||||
|
||||
impl UsageCache {
|
||||
fn find(&mut self, definition: &Definition) -> Option<&FileReferences> {
|
||||
fn find(&mut self, definition: &Definition) -> Option<&UsageSearchResult> {
|
||||
// We expect a very small number of cache entries (generally 1), so a linear scan should be
|
||||
// fast enough and avoids the need to implement Hash for Definition.
|
||||
for (d, refs) in &self.usages {
|
||||
|
Loading…
Reference in New Issue
Block a user