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/lib.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/lib.rs')
-rw-r--r-- | crates/ra_ssr/src/lib.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs index 3009dcb93..b28913a65 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ra_ssr/src/lib.rs | |||
@@ -15,7 +15,6 @@ pub use crate::errors::SsrError; | |||
15 | pub use crate::matching::Match; | 15 | pub use crate::matching::Match; |
16 | use crate::matching::MatchFailureReason; | 16 | use crate::matching::MatchFailureReason; |
17 | use hir::Semantics; | 17 | use hir::Semantics; |
18 | use parsing::SsrTemplate; | ||
19 | use ra_db::{FileId, FileRange}; | 18 | use ra_db::{FileId, FileRange}; |
20 | use ra_syntax::{ast, AstNode, SyntaxNode, TextRange}; | 19 | use ra_syntax::{ast, AstNode, SyntaxNode, TextRange}; |
21 | use ra_text_edit::TextEdit; | 20 | use ra_text_edit::TextEdit; |
@@ -26,7 +25,7 @@ pub struct SsrRule { | |||
26 | /// A structured pattern that we're searching for. | 25 | /// A structured pattern that we're searching for. |
27 | pattern: parsing::RawPattern, | 26 | pattern: parsing::RawPattern, |
28 | /// What we'll replace it with. | 27 | /// What we'll replace it with. |
29 | template: SsrTemplate, | 28 | template: parsing::RawPattern, |
30 | parsed_rules: Vec<parsing::ParsedRule>, | 29 | parsed_rules: Vec<parsing::ParsedRule>, |
31 | } | 30 | } |
32 | 31 | ||
@@ -72,7 +71,11 @@ impl<'db> MatchFinder<'db> { | |||
72 | None | 71 | None |
73 | } else { | 72 | } else { |
74 | use ra_db::SourceDatabaseExt; | 73 | use ra_db::SourceDatabaseExt; |
75 | Some(replacing::matches_to_edit(&matches, &self.sema.db.file_text(file_id))) | 74 | Some(replacing::matches_to_edit( |
75 | &matches, | ||
76 | &self.sema.db.file_text(file_id), | ||
77 | &self.rules, | ||
78 | )) | ||
76 | } | 79 | } |
77 | } | 80 | } |
78 | 81 | ||
@@ -111,9 +114,8 @@ impl<'db> MatchFinder<'db> { | |||
111 | } | 114 | } |
112 | 115 | ||
113 | fn add_parsed_rules(&mut self, parsed_rules: Vec<parsing::ParsedRule>) { | 116 | fn add_parsed_rules(&mut self, parsed_rules: Vec<parsing::ParsedRule>) { |
114 | // FIXME: This doesn't need to be a for loop, but does in a subsequent commit. Justify it | 117 | for mut parsed_rule in parsed_rules { |
115 | // being a for-loop. | 118 | parsed_rule.index = self.rules.len(); |
116 | for parsed_rule in parsed_rules { | ||
117 | self.rules.push(parsed_rule); | 119 | self.rules.push(parsed_rule); |
118 | } | 120 | } |
119 | } | 121 | } |