aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ssr')
-rw-r--r--crates/ssr/src/search.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/crates/ssr/src/search.rs b/crates/ssr/src/search.rs
index a1d653aff..a3eb2e800 100644
--- a/crates/ssr/src/search.rs
+++ b/crates/ssr/src/search.rs
@@ -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, Vec<FileReferences>)>, 23 usages: Vec<(Definition, FileReferences)>,
24} 24}
25 25
26impl<'db> MatchFinder<'db> { 26impl<'db> MatchFinder<'db> {
@@ -58,11 +58,7 @@ impl<'db> MatchFinder<'db> {
58 ) { 58 ) {
59 if let Some(resolved_path) = pick_path_for_usages(pattern) { 59 if let Some(resolved_path) = pick_path_for_usages(pattern) {
60 let definition: Definition = resolved_path.resolution.clone().into(); 60 let definition: Definition = resolved_path.resolution.clone().into();
61 for file_range in self 61 for file_range in self.find_usages(usage_cache, definition).file_ranges() {
62 .find_usages(usage_cache, definition)
63 .iter()
64 .flat_map(FileReferences::file_ranges)
65 {
66 if let Some(node_to_match) = self.find_node_to_match(resolved_path, file_range) { 62 if let Some(node_to_match) = self.find_node_to_match(resolved_path, file_range) {
67 if !is_search_permitted_ancestors(&node_to_match) { 63 if !is_search_permitted_ancestors(&node_to_match) {
68 mark::hit!(use_declaration_with_braces); 64 mark::hit!(use_declaration_with_braces);
@@ -112,7 +108,7 @@ impl<'db> MatchFinder<'db> {
112 &self, 108 &self,
113 usage_cache: &'a mut UsageCache, 109 usage_cache: &'a mut UsageCache,
114 definition: Definition, 110 definition: Definition,
115 ) -> &'a [FileReferences] { 111 ) -> &'a FileReferences {
116 // 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
117 // 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
118 // 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
@@ -254,7 +250,7 @@ fn is_search_permitted(node: &SyntaxNode) -> bool {
254} 250}
255 251
256impl UsageCache { 252impl UsageCache {
257 fn find(&mut self, definition: &Definition) -> Option<&[FileReferences]> { 253 fn find(&mut self, definition: &Definition) -> Option<&FileReferences> {
258 // 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
259 // fast enough and avoids the need to implement Hash for Definition. 255 // fast enough and avoids the need to implement Hash for Definition.
260 for (d, refs) in &self.usages { 256 for (d, refs) in &self.usages {