From aff9102afb2b6756b3935dedb9be30401975b262 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 12 Jan 2021 15:56:24 +0100 Subject: Rename FileReferences -> UsageSearchResult --- crates/ide/src/references.rs | 10 +++++----- crates/ide_db/src/search.rs | 11 +++++------ crates/ssr/src/search.rs | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'crates') 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; 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 @@ use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeI #[derive(Debug, Clone)] pub struct ReferenceSearchResult { declaration: Declaration, - references: FileReferences, + references: UsageSearchResult, } #[derive(Debug, Clone)] @@ -48,11 +48,11 @@ impl ReferenceSearchResult { &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( 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::{ }; #[derive(Debug, Default, Clone)] -pub struct FileReferences { +pub struct UsageSearchResult { pub references: FxHashMap>, } -impl FileReferences { +impl UsageSearchResult { pub fn is_empty(&self) -> bool { self.references.is_empty() } @@ -43,7 +43,7 @@ impl FileReferences { } } -impl IntoIterator for FileReferences { +impl IntoIterator for UsageSearchResult { type Item = (FileId, Vec); type IntoIter = > as IntoIterator>::IntoIter; @@ -293,9 +293,8 @@ impl<'a> FindUsages<'a> { 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 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::{ 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 @@ use test_utils::mark; /// 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 @@ impl<'db> MatchFinder<'db> { &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 { -- cgit v1.2.3