diff options
author | David Lattimore <[email protected]> | 2020-07-22 10:15:19 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-24 12:34:00 +0100 |
commit | 113abbeefee671266d2d9bebdbd517eb8b802ef8 (patch) | |
tree | a7c44c0490b09f06034cb82966b8a61f681c4433 /crates/ra_ssr/src/matching.rs | |
parent | 1fce8b6ba32bebba36d588d07781e9e578845728 (diff) |
SSR: Parse template as Rust code.
This is in preparation for a subsequent commit where we add special
handling for paths in the template, allowing them to be qualified
differently in different contexts.
Diffstat (limited to 'crates/ra_ssr/src/matching.rs')
-rw-r--r-- | crates/ra_ssr/src/matching.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/crates/ra_ssr/src/matching.rs b/crates/ra_ssr/src/matching.rs index 842f4b6f3..486191635 100644 --- a/crates/ra_ssr/src/matching.rs +++ b/crates/ra_ssr/src/matching.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | //! process of matching, placeholder values are recorded. | 2 | //! process of matching, placeholder values are recorded. |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | parsing::{Constraint, NodeKind, ParsedRule, Placeholder, SsrTemplate}, | 5 | parsing::{Constraint, NodeKind, ParsedRule, Placeholder}, |
6 | SsrMatches, | 6 | SsrMatches, |
7 | }; | 7 | }; |
8 | use hir::Semantics; | 8 | use hir::Semantics; |
@@ -48,9 +48,7 @@ pub struct Match { | |||
48 | pub(crate) matched_node: SyntaxNode, | 48 | pub(crate) matched_node: SyntaxNode, |
49 | pub(crate) placeholder_values: FxHashMap<Var, PlaceholderMatch>, | 49 | pub(crate) placeholder_values: FxHashMap<Var, PlaceholderMatch>, |
50 | pub(crate) ignored_comments: Vec<ast::Comment>, | 50 | pub(crate) ignored_comments: Vec<ast::Comment>, |
51 | // A copy of the template for the rule that produced this match. We store this on the match for | 51 | pub(crate) rule_index: usize, |
52 | // if/when we do replacement. | ||
53 | pub(crate) template: Option<SsrTemplate>, | ||
54 | } | 52 | } |
55 | 53 | ||
56 | /// Represents a `$var` in an SSR query. | 54 | /// Represents a `$var` in an SSR query. |
@@ -131,7 +129,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { | |||
131 | matched_node: code.clone(), | 129 | matched_node: code.clone(), |
132 | placeholder_values: FxHashMap::default(), | 130 | placeholder_values: FxHashMap::default(), |
133 | ignored_comments: Vec::new(), | 131 | ignored_comments: Vec::new(), |
134 | template: rule.template.clone(), | 132 | rule_index: rule.index, |
135 | }; | 133 | }; |
136 | // Second matching pass, where we record placeholder matches, ignored comments and maybe do | 134 | // Second matching pass, where we record placeholder matches, ignored comments and maybe do |
137 | // any other more expensive checks that we didn't want to do on the first pass. | 135 | // any other more expensive checks that we didn't want to do on the first pass. |
@@ -591,7 +589,7 @@ mod tests { | |||
591 | "1+2" | 589 | "1+2" |
592 | ); | 590 | ); |
593 | 591 | ||
594 | let edit = crate::replacing::matches_to_edit(&matches, input); | 592 | let edit = crate::replacing::matches_to_edit(&matches, input, &match_finder.rules); |
595 | let mut after = input.to_string(); | 593 | let mut after = input.to_string(); |
596 | edit.apply(&mut after); | 594 | edit.apply(&mut after); |
597 | assert_eq!(after, "fn foo() {} fn main() { bar(1+2); }"); | 595 | assert_eq!(after, "fn foo() {} fn main() { bar(1+2); }"); |