Rename FileReferences -> UsageSearchResult
This commit is contained in:
parent
2c1777a2e2
commit
aff9102afb
@ -15,7 +15,7 @@
|
|||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::FileId,
|
base_db::FileId,
|
||||||
defs::{Definition, NameClass, NameRefClass},
|
defs::{Definition, NameClass, NameRefClass},
|
||||||
search::{FileReference, FileReferences, ReferenceAccess, ReferenceKind, SearchScope},
|
search::{FileReference, ReferenceAccess, ReferenceKind, SearchScope, UsageSearchResult},
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
@ -29,7 +29,7 @@
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ReferenceSearchResult {
|
pub struct ReferenceSearchResult {
|
||||||
declaration: Declaration,
|
declaration: Declaration,
|
||||||
references: FileReferences,
|
references: UsageSearchResult,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -48,11 +48,11 @@ pub fn decl_target(&self) -> &NavigationTarget {
|
|||||||
&self.declaration.nav
|
&self.declaration.nav
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn references(&self) -> &FileReferences {
|
pub fn references(&self) -> &UsageSearchResult {
|
||||||
&self.references
|
&self.references
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn references_with_declaration(mut self) -> FileReferences {
|
pub fn references_with_declaration(mut self) -> UsageSearchResult {
|
||||||
let decl_ref = FileReference {
|
let decl_ref = FileReference {
|
||||||
range: self.declaration.nav.focus_or_full_range(),
|
range: self.declaration.nav.focus_or_full_range(),
|
||||||
kind: self.declaration.kind,
|
kind: self.declaration.kind,
|
||||||
@ -315,7 +315,7 @@ fn try_find_self_references(
|
|||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let mut references = FileReferences::default();
|
let mut references = UsageSearchResult::default();
|
||||||
references.references.insert(file_id, refs);
|
references.references.insert(file_id, refs);
|
||||||
|
|
||||||
Some(RangeInfo::new(
|
Some(RangeInfo::new(
|
||||||
|
@ -19,11 +19,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct FileReferences {
|
pub struct UsageSearchResult {
|
||||||
pub references: FxHashMap<FileId, Vec<FileReference>>,
|
pub references: FxHashMap<FileId, Vec<FileReference>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileReferences {
|
impl UsageSearchResult {
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.references.is_empty()
|
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 Item = (FileId, Vec<FileReference>);
|
||||||
type IntoIter = <FxHashMap<FileId, Vec<FileReference>> as IntoIterator>::IntoIter;
|
type IntoIter = <FxHashMap<FileId, Vec<FileReference>> as IntoIterator>::IntoIter;
|
||||||
|
|
||||||
@ -293,9 +293,8 @@ pub fn at_least_one(self) -> bool {
|
|||||||
found
|
found
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`FileReferences`] returned always have unique [`FileId`]s.
|
pub fn all(self) -> UsageSearchResult {
|
||||||
pub fn all(self) -> FileReferences {
|
let mut res = UsageSearchResult::default();
|
||||||
let mut res = FileReferences::default();
|
|
||||||
self.search(&mut |file_id, reference| {
|
self.search(&mut |file_id, reference| {
|
||||||
res.references.entry(file_id).or_default().push(reference);
|
res.references.entry(file_id).or_default().push(reference);
|
||||||
false
|
false
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{FileId, FileRange},
|
base_db::{FileId, FileRange},
|
||||||
defs::Definition,
|
defs::Definition,
|
||||||
search::{FileReferences, SearchScope},
|
search::{SearchScope, UsageSearchResult},
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use syntax::{ast, AstNode, SyntaxKind, SyntaxNode};
|
use syntax::{ast, AstNode, SyntaxKind, SyntaxNode};
|
||||||
@ -20,7 +20,7 @@
|
|||||||
/// them more than once.
|
/// them more than once.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(crate) struct UsageCache {
|
pub(crate) struct UsageCache {
|
||||||
usages: Vec<(Definition, FileReferences)>,
|
usages: Vec<(Definition, UsageSearchResult)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> MatchFinder<'db> {
|
impl<'db> MatchFinder<'db> {
|
||||||
@ -108,7 +108,7 @@ fn find_usages<'a>(
|
|||||||
&self,
|
&self,
|
||||||
usage_cache: &'a mut UsageCache,
|
usage_cache: &'a mut UsageCache,
|
||||||
definition: Definition,
|
definition: Definition,
|
||||||
) -> &'a FileReferences {
|
) -> &'a UsageSearchResult {
|
||||||
// Logically if a lookup succeeds we should just return it. Unfortunately returning it would
|
// 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
|
// 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
|
// 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 {
|
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
|
// 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.
|
// fast enough and avoids the need to implement Hash for Definition.
|
||||||
for (d, refs) in &self.usages {
|
for (d, refs) in &self.usages {
|
||||||
|
Loading…
Reference in New Issue
Block a user