aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ssr/src/lib.rs
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-07-22 07:48:12 +0100
committerDavid Lattimore <[email protected]>2020-07-24 12:34:00 +0100
commit02fc3d50ee4d179cc5a443a790544c2a5e439cb0 (patch)
treeebef46263fa32fc04f1838b8b6a5191ce8809184 /crates/ra_ssr/src/lib.rs
parent699619a65cf816b927fffa77b2b38f611d8460bc (diff)
SSR: Refactor to not rely on recursive search for nesting of matches
Previously, submatches were handled simply by searching in placeholders for more matches. That only works if we search all nodes in the tree recursively. In a subsequent commit, I intend to make search not always be recursive recursive. This commit prepares for that by finding all matches, even if they overlap, then nesting them and removing overlapping matches.
Diffstat (limited to 'crates/ra_ssr/src/lib.rs')
-rw-r--r--crates/ra_ssr/src/lib.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs
index 7b6409806..6d578610b 100644
--- a/crates/ra_ssr/src/lib.rs
+++ b/crates/ra_ssr/src/lib.rs
@@ -4,6 +4,7 @@
4//! based on a template. 4//! based on a template.
5 5
6mod matching; 6mod matching;
7mod nester;
7mod parsing; 8mod parsing;
8mod replacing; 9mod replacing;
9mod search; 10mod search;
@@ -90,8 +91,10 @@ impl<'db> MatchFinder<'db> {
90 /// Returns matches for all added rules. 91 /// Returns matches for all added rules.
91 pub fn matches(&self) -> SsrMatches { 92 pub fn matches(&self) -> SsrMatches {
92 let mut matches = Vec::new(); 93 let mut matches = Vec::new();
93 self.find_all_matches(&mut matches); 94 for rule in &self.rules {
94 SsrMatches { matches } 95 self.find_matches_for_rule(rule, &mut matches);
96 }
97 nester::nest_and_remove_collisions(matches, &self.sema)
95 } 98 }
96 99
97 /// Finds all nodes in `file_id` whose text is exactly equal to `snippet` and attempts to match 100 /// Finds all nodes in `file_id` whose text is exactly equal to `snippet` and attempts to match