aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/ssr.rs
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-07-22 07:46:29 +0100
committerDavid Lattimore <[email protected]>2020-07-24 12:34:00 +0100
commit757f755c29e041fd319af466d7d0418f54cb090a (patch)
tree30d94206c5009730855a2ceaebdf364963358928 /crates/ra_ide/src/ssr.rs
parent3975952601888d9f77e466c12e8e389748984b33 (diff)
SSR: Match paths based on what they resolve to
Also render template paths appropriately for their context.
Diffstat (limited to 'crates/ra_ide/src/ssr.rs')
-rw-r--r--crates/ra_ide/src/ssr.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index 3e2705d62..2f40bac08 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -11,6 +11,16 @@ use ra_ssr::{MatchFinder, SsrError, SsrRule};
11// A `$<name>` placeholder in the search pattern will match any AST node and `$<name>` will reference it in the replacement. 11// A `$<name>` placeholder in the search pattern will match any AST node and `$<name>` will reference it in the replacement.
12// Within a macro call, a placeholder will match up until whatever token follows the placeholder. 12// Within a macro call, a placeholder will match up until whatever token follows the placeholder.
13// 13//
14// All paths in both the search pattern and the replacement template must resolve in the context
15// in which this command is invoked. Paths in the search pattern will then match the code if they
16// resolve to the same item, even if they're written differently. For example if we invoke the
17// command in the module `foo` with a pattern of `Bar`, then code in the parent module that refers
18// to `foo::Bar` will match.
19//
20// Paths in the replacement template will be rendered appropriately for the context in which the
21// replacement occurs. For example if our replacement template is `foo::Bar` and we match some
22// code in the `foo` module, we'll insert just `Bar`.
23//
14// Placeholders may be given constraints by writing them as `${<name>:<constraint1>:<constraint2>...}`. 24// Placeholders may be given constraints by writing them as `${<name>:<constraint1>:<constraint2>...}`.
15// 25//
16// Supported constraints: 26// Supported constraints:
@@ -47,7 +57,7 @@ pub fn parse_search_replace(
47) -> Result<Vec<SourceFileEdit>, SsrError> { 57) -> Result<Vec<SourceFileEdit>, SsrError> {
48 let rule: SsrRule = rule.parse()?; 58 let rule: SsrRule = rule.parse()?;
49 let mut match_finder = MatchFinder::in_context(db, position); 59 let mut match_finder = MatchFinder::in_context(db, position);
50 match_finder.add_rule(rule); 60 match_finder.add_rule(rule)?;
51 if parse_only { 61 if parse_only {
52 return Ok(Vec::new()); 62 return Ok(Vec::new());
53 } 63 }