aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr/src/replacing.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-21 18:12:38 +0100
committerAleksey Kladov <[email protected]>2020-08-21 18:14:05 +0100
commit863b1fb731e797f02daeac87a94d40a34222a062 (patch)
tree7a3ae3553ad1c97ad4ac70d8b7126ee0ec5343ad /crates/ssr/src/replacing.rs
parentdf54561a689a9eb7b1962b69a397a1221200c116 (diff)
:arrow_up: ungrammar
Diffstat (limited to 'crates/ssr/src/replacing.rs')
-rw-r--r--crates/ssr/src/replacing.rs7
1 files changed, 2 insertions, 5 deletions
diff --git a/crates/ssr/src/replacing.rs b/crates/ssr/src/replacing.rs
index 29284e3f1..7e7ce37bd 100644
--- a/crates/ssr/src/replacing.rs
+++ b/crates/ssr/src/replacing.rs
@@ -3,7 +3,7 @@
3use crate::{resolving::ResolvedRule, Match, SsrMatches}; 3use crate::{resolving::ResolvedRule, Match, SsrMatches};
4use itertools::Itertools; 4use itertools::Itertools;
5use rustc_hash::{FxHashMap, FxHashSet}; 5use rustc_hash::{FxHashMap, FxHashSet};
6use syntax::ast::{self, AstToken}; 6use syntax::ast::{self, AstNode, AstToken};
7use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize}; 7use syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, TextRange, TextSize};
8use test_utils::mark; 8use test_utils::mark;
9use text_edit::TextEdit; 9use text_edit::TextEdit;
@@ -93,7 +93,6 @@ impl ReplacementRenderer<'_> {
93 } 93 }
94 94
95 fn render_node(&mut self, node: &SyntaxNode) { 95 fn render_node(&mut self, node: &SyntaxNode) {
96 use syntax::ast::AstNode;
97 if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) { 96 if let Some(mod_path) = self.match_info.rendered_template_paths.get(&node) {
98 self.out.push_str(&mod_path.to_string()); 97 self.out.push_str(&mod_path.to_string());
99 // Emit everything except for the segment's name-ref, since we already effectively 98 // Emit everything except for the segment's name-ref, since we already effectively
@@ -206,11 +205,10 @@ impl ReplacementRenderer<'_> {
206/// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while 205/// method call doesn't count. e.g. if the token is `$a`, then `$a.foo()` will return true, while
207/// `($a + $b).foo()` or `x.foo($a)` will return false. 206/// `($a + $b).foo()` or `x.foo($a)` will return false.
208fn token_is_method_call_receiver(token: &SyntaxToken) -> bool { 207fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
209 use syntax::ast::AstNode;
210 // Find the first method call among the ancestors of `token`, then check if the only token 208 // Find the first method call among the ancestors of `token`, then check if the only token
211 // within the receiver is `token`. 209 // within the receiver is `token`.
212 if let Some(receiver) = 210 if let Some(receiver) =
213 token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.expr()) 211 token.ancestors().find_map(ast::MethodCallExpr::cast).and_then(|call| call.receiver())
214 { 212 {
215 let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| { 213 let tokens = receiver.syntax().descendants_with_tokens().filter_map(|node_or_token| {
216 match node_or_token { 214 match node_or_token {
@@ -226,7 +224,6 @@ fn token_is_method_call_receiver(token: &SyntaxToken) -> bool {
226} 224}
227 225
228fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option<SyntaxNode> { 226fn parse_as_kind(code: &str, kind: SyntaxKind) -> Option<SyntaxNode> {
229 use syntax::ast::AstNode;
230 if ast::Expr::can_cast(kind) { 227 if ast::Expr::can_cast(kind) {
231 if let Ok(expr) = ast::Expr::parse(code) { 228 if let Ok(expr) = ast::Expr::parse(code) {
232 return Some(expr.syntax().clone()); 229 return Some(expr.syntax().clone());