diff options
author | David Lattimore <[email protected]> | 2020-07-29 02:44:01 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-29 06:06:58 +0100 |
commit | cf55806257776baf7db6b02d260bdaa9e851c7d4 (patch) | |
tree | 6827c094a4a27631ee9b1b97d98a8ac9c0a56aac /crates/ra_ide/src/ssr.rs | |
parent | 5a8124273dd663f7f1ed43b53defc4a2c52dbc12 (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/src/ssr.rs')
-rw-r--r-- | crates/ra_ide/src/ssr.rs | 8 |
1 files changed, 6 insertions, 2 deletions
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 @@ | |||
1 | use ra_db::FilePosition; | 1 | use ra_db::{FilePosition, FileRange}; |
2 | use ra_ide_db::RootDatabase; | 2 | use ra_ide_db::RootDatabase; |
3 | 3 | ||
4 | use crate::SourceFileEdit; | 4 | use 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()); |