aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/search.rs
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-08-01 08:41:42 +0100
committerDavid Lattimore <[email protected]>2020-08-01 08:41:42 +0100
commit6bbeffc8c56893548f5667844f59ce5a76f9fd98 (patch)
tree446162072916f99a3c9b4c5e1734fbcc56cbd3f1 /crates/ra_ssr/src/search.rs
parent5af32aeb2b83c7ae8adf3e088bf4f3691aa45eb1 (diff)
SSR: Allow `self` in patterns.
It's now consistent with other variables in that if the pattern references self, only the `self` in scope where the rule is invoked will be accepted. Since `self` doesn't work the same as other paths, this is implemented by restricting the search to just the current function. Prior to this change (since path resolution was implemented), having self in a pattern would just result in no matches.
Diffstat (limited to 'crates/ra_ssr/src/search.rs')
-rw-r--r--crates/ra_ssr/src/search.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/search.rs b/crates/ra_ssr/src/search.rs
index 213dc494f..85ffa2ac2 100644
--- a/crates/ra_ssr/src/search.rs
+++ b/crates/ra_ssr/src/search.rs
@@ -33,6 +33,15 @@ impl<'db> MatchFinder<'db> {
33 usage_cache: &mut UsageCache, 33 usage_cache: &mut UsageCache,
34 matches_out: &mut Vec<Match>, 34 matches_out: &mut Vec<Match>,
35 ) { 35 ) {
36 if rule.pattern.contains_self {
37 // If the pattern contains `self` we restrict the scope of the search to just the
38 // current method. No other method can reference the same `self`. This makes the
39 // behavior of `self` consistent with other variables.
40 if let Some(current_function) = self.resolution_scope.current_function() {
41 self.slow_scan_node(&current_function, rule, &None, matches_out);
42 }
43 return;
44 }
36 if pick_path_for_usages(&rule.pattern).is_none() { 45 if pick_path_for_usages(&rule.pattern).is_none() {
37 self.slow_scan(rule, matches_out); 46 self.slow_scan(rule, matches_out);
38 return; 47 return;