From 02fc3d50ee4d179cc5a443a790544c2a5e439cb0 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Wed, 22 Jul 2020 16:48:12 +1000 Subject: 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. --- crates/ra_ssr/src/matching.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_ssr/src/matching.rs') 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 { pub(crate) placeholder_values: FxHashMap, pub(crate) ignored_comments: Vec, pub(crate) rule_index: usize, + /// The depth of matched_node. + pub(crate) depth: usize, } /// Represents a `$var` in an SSR query. @@ -130,10 +132,12 @@ impl<'db, 'sema> Matcher<'db, 'sema> { placeholder_values: FxHashMap::default(), ignored_comments: Vec::new(), rule_index: rule.index, + depth: 0, }; // Second matching pass, where we record placeholder matches, ignored comments and maybe do // any other more expensive checks that we didn't want to do on the first pass. match_state.attempt_match_node(&mut Phase::Second(&mut the_match), &rule.pattern, code)?; + the_match.depth = sema.ancestors_with_macros(the_match.matched_node.clone()).count(); Ok(the_match) } -- cgit v1.2.3