aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-29 10:23:33 +0100
committerGitHub <[email protected]>2020-07-29 10:23:33 +0100
commit9a9ddcc29793e5ba3bfece096e222736e2172555 (patch)
tree929b74f0646996d84351dfbc1974ed762eaa847b /crates/ra_ide
parent04d2b7b256657f8e6816f8ed67aa5608bfe9e261 (diff)
parentfcb6b166fbc506950dc2689adfa4d0b728d1a745 (diff)
Merge #5564
5564: SSR: Restrict to current selection if any r=davidlattimore a=davidlattimore The selection is also used to avoid unnecessary work, but only to the file level. Further restricting unnecessary work is left for later. Co-authored-by: David Lattimore <[email protected]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/lib.rs3
-rw-r--r--crates/ra_ide/src/ssr.rs10
2 files changed, 9 insertions, 4 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 4c4d9f6fa..0fede0d87 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -510,9 +510,10 @@ impl Analysis {
510 query: &str, 510 query: &str,
511 parse_only: bool, 511 parse_only: bool,
512 position: FilePosition, 512 position: FilePosition,
513 selections: Vec<FileRange>,
513 ) -> Cancelable<Result<SourceChange, SsrError>> { 514 ) -> Cancelable<Result<SourceChange, SsrError>> {
514 self.with_db(|db| { 515 self.with_db(|db| {
515 let edits = ssr::parse_search_replace(query, parse_only, db, position)?; 516 let edits = ssr::parse_search_replace(query, parse_only, db, position, selections)?;
516 Ok(SourceChange::from(edits)) 517 Ok(SourceChange::from(edits))
517 }) 518 })
518 } 519 }
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index 95d8f79b8..4348b43be 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -1,4 +1,4 @@
1use ra_db::FilePosition; 1use ra_db::{FilePosition, FileRange};
2use ra_ide_db::RootDatabase; 2use ra_ide_db::RootDatabase;
3 3
4use crate::SourceFileEdit; 4use crate::SourceFileEdit;
@@ -24,6 +24,9 @@ use ra_ssr::{MatchFinder, SsrError, SsrRule};
24// Method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will match 24// Method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will match
25// `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`. 25// `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`.
26// 26//
27// The scope of the search / replace will be restricted to the current selection if any, otherwise
28// it will apply to the whole workspace.
29//
27// Placeholders may be given constraints by writing them as `${<name>:<constraint1>:<constraint2>...}`. 30// Placeholders may be given constraints by writing them as `${<name>:<constraint1>:<constraint2>...}`.
28// 31//
29// Supported constraints: 32// Supported constraints:
@@ -56,10 +59,11 @@ pub fn parse_search_replace(
56 rule: &str, 59 rule: &str,
57 parse_only: bool, 60 parse_only: bool,
58 db: &RootDatabase, 61 db: &RootDatabase,
59 position: FilePosition, 62 resolve_context: FilePosition,
63 selections: Vec<FileRange>,
60) -> Result<Vec<SourceFileEdit>, SsrError> { 64) -> Result<Vec<SourceFileEdit>, SsrError> {
61 let rule: SsrRule = rule.parse()?; 65 let rule: SsrRule = rule.parse()?;
62 let mut match_finder = MatchFinder::in_context(db, position); 66 let mut match_finder = MatchFinder::in_context(db, resolve_context, selections);
63 match_finder.add_rule(rule)?; 67 match_finder.add_rule(rule)?;
64 if parse_only { 68 if parse_only {
65 return Ok(Vec::new()); 69 return Ok(Vec::new());