aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide/src/references.rs10
-rw-r--r--crates/ide_db/src/search.rs11
-rw-r--r--crates/ssr/src/search.rs8
3 files changed, 14 insertions, 15 deletions
diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs
index c7943dc95..7d4757e02 100644
--- a/crates/ide/src/references.rs
+++ b/crates/ide/src/references.rs
@@ -15,7 +15,7 @@ use hir::Semantics;
15use ide_db::{ 15use ide_db::{
16 base_db::FileId, 16 base_db::FileId,
17 defs::{Definition, NameClass, NameRefClass}, 17 defs::{Definition, NameClass, NameRefClass},
18 search::{FileReference, FileReferences, ReferenceAccess, ReferenceKind, SearchScope}, 18 search::{FileReference, ReferenceAccess, ReferenceKind, SearchScope, UsageSearchResult},
19 RootDatabase, 19 RootDatabase,
20}; 20};
21use syntax::{ 21use syntax::{
@@ -29,7 +29,7 @@ use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeI
29#[derive(Debug, Clone)] 29#[derive(Debug, Clone)]
30pub struct ReferenceSearchResult { 30pub struct ReferenceSearchResult {
31 declaration: Declaration, 31 declaration: Declaration,
32 references: FileReferences, 32 references: UsageSearchResult,
33} 33}
34 34
35#[derive(Debug, Clone)] 35#[derive(Debug, Clone)]
@@ -48,11 +48,11 @@ impl ReferenceSearchResult {
48 &self.declaration.nav 48 &self.declaration.nav
49 } 49 }
50 50
51 pub fn references(&self) -> &FileReferences { 51 pub fn references(&self) -> &UsageSearchResult {
52 &self.references 52 &self.references
53 } 53 }
54 54
55 pub fn references_with_declaration(mut self) -> FileReferences { 55 pub fn references_with_declaration(mut self) -> UsageSearchResult {
56 let decl_ref = FileReference { 56 let decl_ref = FileReference {
57 range: self.declaration.nav.focus_or_full_range(), 57 range: self.declaration.nav.focus_or_full_range(),
58 kind: self.declaration.kind, 58 kind: self.declaration.kind,
@@ -315,7 +315,7 @@ fn try_find_self_references(
315 .collect() 315 .collect()
316 }) 316 })
317 .unwrap_or_default(); 317 .unwrap_or_default();
318 let mut references = FileReferences::default(); 318 let mut references = UsageSearchResult::default();
319 references.references.insert(file_id, refs); 319 references.references.insert(file_id, refs);
320 320
321 Some(RangeInfo::new( 321 Some(RangeInfo::new(
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 89a313e9b..b5fa46642 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -19,11 +19,11 @@ use crate::{
19}; 19};
20 20
21#[derive(Debug, Default, Clone)] 21#[derive(Debug, Default, Clone)]
22pub struct FileReferences { 22pub struct UsageSearchResult {
23 pub references: FxHashMap<FileId, Vec<FileReference>>, 23 pub references: FxHashMap<FileId, Vec<FileReference>>,
24} 24}
25 25
26impl FileReferences { 26impl UsageSearchResult {
27 pub fn is_empty(&self) -> bool { 27 pub fn is_empty(&self) -> bool {
28 self.references.is_empty() 28 self.references.is_empty()
29 } 29 }
@@ -43,7 +43,7 @@ impl FileReferences {
43 } 43 }
44} 44}
45 45
46impl IntoIterator for FileReferences { 46impl IntoIterator for UsageSearchResult {
47 type Item = (FileId, Vec<FileReference>); 47 type Item = (FileId, Vec<FileReference>);
48 type IntoIter = <FxHashMap<FileId, Vec<FileReference>> as IntoIterator>::IntoIter; 48 type IntoIter = <FxHashMap<FileId, Vec<FileReference>> as IntoIterator>::IntoIter;
49 49
@@ -293,9 +293,8 @@ impl<'a> FindUsages<'a> {
293 found 293 found
294 } 294 }
295 295
296 /// The [`FileReferences`] returned always have unique [`FileId`]s. 296 pub fn all(self) -> UsageSearchResult {
297 pub fn all(self) -> FileReferences { 297 let mut res = UsageSearchResult::default();
298 let mut res = FileReferences::default();
299 self.search(&mut |file_id, reference| { 298 self.search(&mut |file_id, reference| {
300 res.references.entry(file_id).or_default().push(reference); 299 res.references.entry(file_id).or_default().push(reference);
301 false 300 false
diff --git a/crates/ssr/src/search.rs b/crates/ssr/src/search.rs
index a3eb2e800..836eb94b2 100644
--- a/crates/ssr/src/search.rs
+++ b/crates/ssr/src/search.rs
@@ -8,7 +8,7 @@ use crate::{
8use ide_db::{ 8use ide_db::{
9 base_db::{FileId, FileRange}, 9 base_db::{FileId, FileRange},
10 defs::Definition, 10 defs::Definition,
11 search::{FileReferences, SearchScope}, 11 search::{SearchScope, UsageSearchResult},
12}; 12};
13use rustc_hash::FxHashSet; 13use rustc_hash::FxHashSet;
14use syntax::{ast, AstNode, SyntaxKind, SyntaxNode}; 14use syntax::{ast, AstNode, SyntaxKind, SyntaxNode};
@@ -20,7 +20,7 @@ use test_utils::mark;
20/// them more than once. 20/// them more than once.
21#[derive(Default)] 21#[derive(Default)]
22pub(crate) struct UsageCache { 22pub(crate) struct UsageCache {
23 usages: Vec<(Definition, FileReferences)>, 23 usages: Vec<(Definition, UsageSearchResult)>,
24} 24}
25 25
26impl<'db> MatchFinder<'db> { 26impl<'db> MatchFinder<'db> {
@@ -108,7 +108,7 @@ impl<'db> MatchFinder<'db> {
108 &self, 108 &self,
109 usage_cache: &'a mut UsageCache, 109 usage_cache: &'a mut UsageCache,
110 definition: Definition, 110 definition: Definition,
111 ) -> &'a FileReferences { 111 ) -> &'a UsageSearchResult {
112 // Logically if a lookup succeeds we should just return it. Unfortunately returning it would 112 // Logically if a lookup succeeds we should just return it. Unfortunately returning it would
113 // extend the lifetime of the borrow, then we wouldn't be able to do the insertion on a 113 // extend the lifetime of the borrow, then we wouldn't be able to do the insertion on a
114 // cache miss. This is a limitation of NLL and is fixed with Polonius. For now we do two 114 // 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 {
250} 250}
251 251
252impl UsageCache { 252impl UsageCache {
253 fn find(&mut self, definition: &Definition) -> Option<&FileReferences> { 253 fn find(&mut self, definition: &Definition) -> Option<&UsageSearchResult> {
254 // We expect a very small number of cache entries (generally 1), so a linear scan should be 254 // We expect a very small number of cache entries (generally 1), so a linear scan should be
255 // fast enough and avoids the need to implement Hash for Definition. 255 // fast enough and avoids the need to implement Hash for Definition.
256 for (d, refs) in &self.usages { 256 for (d, refs) in &self.usages {