diff options
author | David Lattimore <[email protected]> | 2020-07-22 07:48:12 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-07-24 12:34:00 +0100 |
commit | 02fc3d50ee4d179cc5a443a790544c2a5e439cb0 (patch) | |
tree | ebef46263fa32fc04f1838b8b6a5191ce8809184 /crates/ra_ssr/src/matching.rs | |
parent | 699619a65cf816b927fffa77b2b38f611d8460bc (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/matching.rs')
-rw-r--r-- | crates/ra_ssr/src/matching.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/crates/ra_ssr/src/matching.rs b/crates/ra_ssr/src/matching.rs index 064e3a204..005569f6f 100644 --- a/crates/ra_ssr/src/matching.rs +++ b/crates/ra_ssr/src/matching.rs | |||
@@ -49,6 +49,8 @@ pub struct Match { | |||
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 | pub(crate) rule_index: usize, | 51 | pub(crate) rule_index: usize, |
52 | /// The depth of matched_node. | ||
53 | pub(crate) depth: usize, | ||
52 | } | 54 | } |
53 | 55 | ||
54 | /// Represents a `$var` in an SSR query. | 56 | /// Represents a `$var` in an SSR query. |
@@ -130,10 +132,12 @@ impl<'db, 'sema> Matcher<'db, 'sema> { | |||
130 | placeholder_values: FxHashMap::default(), | 132 | placeholder_values: FxHashMap::default(), |
131 | ignored_comments: Vec::new(), | 133 | ignored_comments: Vec::new(), |
132 | rule_index: rule.index, | 134 | rule_index: rule.index, |
135 | depth: 0, | ||
133 | }; | 136 | }; |
134 | // Second matching pass, where we record placeholder matches, ignored comments and maybe do | 137 | // Second matching pass, where we record placeholder matches, ignored comments and maybe do |
135 | // any other more expensive checks that we didn't want to do on the first pass. | 138 | // any other more expensive checks that we didn't want to do on the first pass. |
136 | match_state.attempt_match_node(&mut Phase::Second(&mut the_match), &rule.pattern, code)?; | 139 | match_state.attempt_match_node(&mut Phase::Second(&mut the_match), &rule.pattern, code)?; |
140 | the_match.depth = sema.ancestors_with_macros(the_match.matched_node.clone()).count(); | ||
137 | Ok(the_match) | 141 | Ok(the_match) |
138 | } | 142 | } |
139 | 143 | ||