aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-07-29 02:44:01 +0100
committerDavid Lattimore <[email protected]>2020-07-29 06:06:58 +0100
commitcf55806257776baf7db6b02d260bdaa9e851c7d4 (patch)
tree6827c094a4a27631ee9b1b97d98a8ac9c0a56aac /crates/ra_ide
parent5a8124273dd663f7f1ed43b53defc4a2c52dbc12 (diff)
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.
Diffstat (limited to 'crates/ra_ide')
-rw-r--r--crates/ra_ide/src/lib.rs3
-rw-r--r--crates/ra_ide/src/ssr.rs8
2 files changed, 8 insertions, 3 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..63010677a 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:
@@ -57,9 +60,10 @@ pub fn parse_search_replace(
57 parse_only: bool, 60 parse_only: bool,
58 db: &RootDatabase, 61 db: &RootDatabase,
59 position: FilePosition, 62 position: 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, position, 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());