diff options
author | David Lattimore <[email protected]> | 2020-07-22 05:01:21 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-24 12:34:00 +0100 |
commit | 63f500b0ee55443a52f078060004c911a7532a14 (patch) | |
tree | 7944b776eea1eb69e4d822f5c004d5f082acd9b8 /crates/ra_ssr/src/resolving.rs | |
parent | 757f755c29e041fd319af466d7d0418f54cb090a (diff) |
SSR: Use Definition::find_usages to speed up matching.
When the search pattern contains a path, this substantially speeds up finding matches, especially if the path references a private item.
Diffstat (limited to 'crates/ra_ssr/src/resolving.rs')
-rw-r--r-- | crates/ra_ssr/src/resolving.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/ra_ssr/src/resolving.rs b/crates/ra_ssr/src/resolving.rs index e9d052111..63fd217ce 100644 --- a/crates/ra_ssr/src/resolving.rs +++ b/crates/ra_ssr/src/resolving.rs | |||
@@ -22,6 +22,7 @@ pub(crate) struct ResolvedPattern { | |||
22 | 22 | ||
23 | pub(crate) struct ResolvedPath { | 23 | pub(crate) struct ResolvedPath { |
24 | pub(crate) resolution: hir::PathResolution, | 24 | pub(crate) resolution: hir::PathResolution, |
25 | pub(crate) depth: u32, | ||
25 | } | 26 | } |
26 | 27 | ||
27 | impl ResolvedRule { | 28 | impl ResolvedRule { |
@@ -62,7 +63,7 @@ struct Resolver<'a, 'db> { | |||
62 | impl Resolver<'_, '_> { | 63 | impl Resolver<'_, '_> { |
63 | fn resolve_pattern_tree(&self, pattern: SyntaxNode) -> Result<ResolvedPattern, SsrError> { | 64 | fn resolve_pattern_tree(&self, pattern: SyntaxNode) -> Result<ResolvedPattern, SsrError> { |
64 | let mut resolved_paths = FxHashMap::default(); | 65 | let mut resolved_paths = FxHashMap::default(); |
65 | self.resolve(pattern.clone(), &mut resolved_paths)?; | 66 | self.resolve(pattern.clone(), 0, &mut resolved_paths)?; |
66 | Ok(ResolvedPattern { | 67 | Ok(ResolvedPattern { |
67 | node: pattern, | 68 | node: pattern, |
68 | resolved_paths, | 69 | resolved_paths, |
@@ -73,6 +74,7 @@ impl Resolver<'_, '_> { | |||
73 | fn resolve( | 74 | fn resolve( |
74 | &self, | 75 | &self, |
75 | node: SyntaxNode, | 76 | node: SyntaxNode, |
77 | depth: u32, | ||
76 | resolved_paths: &mut FxHashMap<SyntaxNode, ResolvedPath>, | 78 | resolved_paths: &mut FxHashMap<SyntaxNode, ResolvedPath>, |
77 | ) -> Result<(), SsrError> { | 79 | ) -> Result<(), SsrError> { |
78 | use ra_syntax::ast::AstNode; | 80 | use ra_syntax::ast::AstNode; |
@@ -86,12 +88,12 @@ impl Resolver<'_, '_> { | |||
86 | let resolution = self | 88 | let resolution = self |
87 | .resolve_path(&path) | 89 | .resolve_path(&path) |
88 | .ok_or_else(|| error!("Failed to resolve path `{}`", node.text()))?; | 90 | .ok_or_else(|| error!("Failed to resolve path `{}`", node.text()))?; |
89 | resolved_paths.insert(node, ResolvedPath { resolution }); | 91 | resolved_paths.insert(node, ResolvedPath { resolution, depth }); |
90 | return Ok(()); | 92 | return Ok(()); |
91 | } | 93 | } |
92 | } | 94 | } |
93 | for node in node.children() { | 95 | for node in node.children() { |
94 | self.resolve(node, resolved_paths)?; | 96 | self.resolve(node, depth + 1, resolved_paths)?; |
95 | } | 97 | } |
96 | Ok(()) | 98 | Ok(()) |
97 | } | 99 | } |