diff options
author | David Lattimore <[email protected]> | 2020-06-23 09:59:18 +0100 |
---|---|---|
committer | David Lattimore <[email protected]> | 2020-06-27 02:33:00 +0100 |
commit | f4dc54958257ad33fe182d600c418591341c86dd (patch) | |
tree | a250def8c836e089a6b296db9502f24a45c92061 /crates/ra_ssr/src/lib.rs | |
parent | 9a4d02faf9c47f401b8756c3f7fcab2198f5f9cd (diff) |
SSR: Allow matching within macro calls
Diffstat (limited to 'crates/ra_ssr/src/lib.rs')
-rw-r--r-- | crates/ra_ssr/src/lib.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_ssr/src/lib.rs b/crates/ra_ssr/src/lib.rs index da26ee669..8f149e3db 100644 --- a/crates/ra_ssr/src/lib.rs +++ b/crates/ra_ssr/src/lib.rs | |||
@@ -12,7 +12,7 @@ mod tests; | |||
12 | use crate::matching::Match; | 12 | use crate::matching::Match; |
13 | use hir::Semantics; | 13 | use hir::Semantics; |
14 | use ra_db::{FileId, FileRange}; | 14 | use ra_db::{FileId, FileRange}; |
15 | use ra_syntax::{AstNode, SmolStr, SyntaxNode}; | 15 | use ra_syntax::{ast, AstNode, SmolStr, SyntaxNode}; |
16 | use ra_text_edit::TextEdit; | 16 | use ra_text_edit::TextEdit; |
17 | use rustc_hash::FxHashMap; | 17 | use rustc_hash::FxHashMap; |
18 | 18 | ||
@@ -107,6 +107,22 @@ impl<'db> MatchFinder<'db> { | |||
107 | return; | 107 | return; |
108 | } | 108 | } |
109 | } | 109 | } |
110 | // If we've got a macro call, we already tried matching it pre-expansion, which is the only | ||
111 | // way to match the whole macro, now try expanding it and matching the expansion. | ||
112 | if let Some(macro_call) = ast::MacroCall::cast(code.clone()) { | ||
113 | if let Some(expanded) = self.sema.expand(¯o_call) { | ||
114 | if let Some(tt) = macro_call.token_tree() { | ||
115 | // When matching within a macro expansion, we only want to allow matches of | ||
116 | // nodes that originated entirely from within the token tree of the macro call. | ||
117 | // i.e. we don't want to match something that came from the macro itself. | ||
118 | self.find_matches( | ||
119 | &expanded, | ||
120 | &Some(self.sema.original_range(tt.syntax())), | ||
121 | matches_out, | ||
122 | ); | ||
123 | } | ||
124 | } | ||
125 | } | ||
110 | for child in code.children() { | 126 | for child in code.children() { |
111 | self.find_matches(&child, restrict_range, matches_out); | 127 | self.find_matches(&child, restrict_range, matches_out); |
112 | } | 128 | } |