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_ide/src/ssr.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/ssr.rs') diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 95d8f79b8..63010677a 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -1,4 +1,4 @@ -use ra_db::FilePosition; +use ra_db::{FilePosition, FileRange}; use ra_ide_db::RootDatabase; use crate::SourceFileEdit; @@ -24,6 +24,9 @@ use ra_ssr::{MatchFinder, SsrError, SsrRule}; // Method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will match // `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`. // +// The scope of the search / replace will be restricted to the current selection if any, otherwise +// it will apply to the whole workspace. +// // Placeholders may be given constraints by writing them as `${::...}`. // // Supported constraints: @@ -57,9 +60,10 @@ pub fn parse_search_replace( parse_only: bool, db: &RootDatabase, position: FilePosition, + selections: Vec, ) -> Result, SsrError> { let rule: SsrRule = rule.parse()?; - let mut match_finder = MatchFinder::in_context(db, position); + let mut match_finder = MatchFinder::in_context(db, position, selections); match_finder.add_rule(rule)?; if parse_only { return Ok(Vec::new()); -- cgit v1.2.3 From fcb6b166fbc506950dc2689adfa4d0b728d1a745 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Wed, 29 Jul 2020 19:20:40 +1000 Subject: SSR: Rename position and lookup_context to resolve_context --- crates/ra_ide/src/ssr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/ssr.rs') diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 63010677a..4348b43be 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -59,11 +59,11 @@ pub fn parse_search_replace( rule: &str, parse_only: bool, db: &RootDatabase, - position: FilePosition, + resolve_context: FilePosition, selections: Vec, ) -> Result, SsrError> { let rule: SsrRule = rule.parse()?; - let mut match_finder = MatchFinder::in_context(db, position, selections); + let mut match_finder = MatchFinder::in_context(db, resolve_context, selections); match_finder.add_rule(rule)?; if parse_only { return Ok(Vec::new()); -- cgit v1.2.3