From cf55806257776baf7db6b02d260bdaa9e851c7d4 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Wed, 29 Jul 2020 11:44:01 +1000 Subject: SSR: Restrict to current selection if any The selection is also used to avoid unnecessary work, but only to the file level. Further restricting unnecessary work is left for later. --- crates/ra_ssr/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/ra_ssr/src/lib.rs') diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs index 7014a6ac6..73abfecb2 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ra_ssr/src/lib.rs @@ -52,6 +52,7 @@ pub struct MatchFinder<'db> { sema: Semantics<'db, ra_ide_db::RootDatabase>, rules: Vec, resolution_scope: resolving::ResolutionScope<'db>, + restrict_ranges: Vec, } impl<'db> MatchFinder<'db> { @@ -60,10 +61,17 @@ impl<'db> MatchFinder<'db> { pub fn in_context( db: &'db ra_ide_db::RootDatabase, lookup_context: FilePosition, + mut restrict_ranges: Vec, ) -> MatchFinder<'db> { + restrict_ranges.retain(|range| !range.range.is_empty()); let sema = Semantics::new(db); let resolution_scope = resolving::ResolutionScope::new(&sema, lookup_context); - MatchFinder { sema: Semantics::new(db), rules: Vec::new(), resolution_scope } + MatchFinder { + sema: Semantics::new(db), + rules: Vec::new(), + resolution_scope, + restrict_ranges, + } } /// Constructs an instance using the start of the first file in `db` as the lookup context. @@ -79,6 +87,7 @@ impl<'db> MatchFinder<'db> { Ok(MatchFinder::in_context( db, FilePosition { file_id: first_file_id, offset: 0.into() }, + vec![], )) } else { bail!("No files to search"); -- cgit v1.2.3 From 6bbeffc8c56893548f5667844f59ce5a76f9fd98 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Sat, 1 Aug 2020 17:41:42 +1000 Subject: 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. --- crates/ra_ssr/src/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'crates/ra_ssr/src/lib.rs') diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs index 73abfecb2..c780b460a 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ra_ssr/src/lib.rs @@ -66,12 +66,7 @@ impl<'db> MatchFinder<'db> { restrict_ranges.retain(|range| !range.range.is_empty()); let sema = Semantics::new(db); let resolution_scope = resolving::ResolutionScope::new(&sema, lookup_context); - MatchFinder { - sema: Semantics::new(db), - rules: Vec::new(), - resolution_scope, - restrict_ranges, - } + MatchFinder { sema, rules: Vec::new(), resolution_scope, restrict_ranges } } /// Constructs an instance using the start of the first file in `db` as the lookup context. -- cgit v1.2.3