aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/ast_transform.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-12 17:31:42 +0100
committerGitHub <[email protected]>2020-08-12 17:31:42 +0100
commitd583f2c46d22cf8d643ebf98be9cb7059a304431 (patch)
tree9d898eb9600b0c36a74e4f95238f679c683fa566 /crates/ra_assists/src/ast_transform.rs
parent3d6889cba72a9d02199f7adaa2ecc69bc30af834 (diff)
parenta1c187eef3ba08076aedb5154929f7eda8d1b424 (diff)
Merge #5729
5729: Rename ra_syntax -> syntax r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/ast_transform.rs')
-rw-r--r--crates/ra_assists/src/ast_transform.rs22
1 files changed, 8 insertions, 14 deletions
diff --git a/crates/ra_assists/src/ast_transform.rs b/crates/ra_assists/src/ast_transform.rs
index 07c978378..4c41c16d8 100644
--- a/crates/ra_assists/src/ast_transform.rs
+++ b/crates/ra_assists/src/ast_transform.rs
@@ -2,13 +2,13 @@
2use rustc_hash::FxHashMap; 2use rustc_hash::FxHashMap;
3 3
4use hir::{HirDisplay, PathResolution, SemanticsScope}; 4use hir::{HirDisplay, PathResolution, SemanticsScope};
5use ra_syntax::{ 5use syntax::{
6 algo::SyntaxRewriter, 6 algo::SyntaxRewriter,
7 ast::{self, AstNode}, 7 ast::{self, AstNode},
8}; 8};
9 9
10pub trait AstTransform<'a> { 10pub trait AstTransform<'a> {
11 fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode>; 11 fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode>;
12 12
13 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a>; 13 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a>;
14 fn or<T: AstTransform<'a> + 'a>(self, other: T) -> Box<dyn AstTransform<'a> + 'a> 14 fn or<T: AstTransform<'a> + 'a>(self, other: T) -> Box<dyn AstTransform<'a> + 'a>
@@ -22,7 +22,7 @@ pub trait AstTransform<'a> {
22struct NullTransformer; 22struct NullTransformer;
23 23
24impl<'a> AstTransform<'a> for NullTransformer { 24impl<'a> AstTransform<'a> for NullTransformer {
25 fn get_substitution(&self, _node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> { 25 fn get_substitution(&self, _node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
26 None 26 None
27 } 27 }
28 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> { 28 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
@@ -101,10 +101,7 @@ impl<'a> SubstituteTypeParams<'a> {
101 Some(result) 101 Some(result)
102 } 102 }
103 } 103 }
104 fn get_substitution_inner( 104 fn get_substitution_inner(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
105 &self,
106 node: &ra_syntax::SyntaxNode,
107 ) -> Option<ra_syntax::SyntaxNode> {
108 let type_ref = ast::Type::cast(node.clone())?; 105 let type_ref = ast::Type::cast(node.clone())?;
109 let path = match &type_ref { 106 let path = match &type_ref {
110 ast::Type::PathType(path_type) => path_type.path()?, 107 ast::Type::PathType(path_type) => path_type.path()?,
@@ -122,7 +119,7 @@ impl<'a> SubstituteTypeParams<'a> {
122} 119}
123 120
124impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> { 121impl<'a> AstTransform<'a> for SubstituteTypeParams<'a> {
125 fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> { 122 fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
126 self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node)) 123 self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
127 } 124 }
128 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> { 125 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {
@@ -141,10 +138,7 @@ impl<'a> QualifyPaths<'a> {
141 Self { target_scope, source_scope, previous: Box::new(NullTransformer) } 138 Self { target_scope, source_scope, previous: Box::new(NullTransformer) }
142 } 139 }
143 140
144 fn get_substitution_inner( 141 fn get_substitution_inner(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
145 &self,
146 node: &ra_syntax::SyntaxNode,
147 ) -> Option<ra_syntax::SyntaxNode> {
148 // FIXME handle value ns? 142 // FIXME handle value ns?
149 let from = self.target_scope.module()?; 143 let from = self.target_scope.module()?;
150 let p = ast::Path::cast(node.clone())?; 144 let p = ast::Path::cast(node.clone())?;
@@ -183,7 +177,7 @@ impl<'a> QualifyPaths<'a> {
183 177
184pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N { 178pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
185 SyntaxRewriter::from_fn(|element| match element { 179 SyntaxRewriter::from_fn(|element| match element {
186 ra_syntax::SyntaxElement::Node(n) => { 180 syntax::SyntaxElement::Node(n) => {
187 let replacement = transformer.get_substitution(&n)?; 181 let replacement = transformer.get_substitution(&n)?;
188 Some(replacement.into()) 182 Some(replacement.into())
189 } 183 }
@@ -193,7 +187,7 @@ pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
193} 187}
194 188
195impl<'a> AstTransform<'a> for QualifyPaths<'a> { 189impl<'a> AstTransform<'a> for QualifyPaths<'a> {
196 fn get_substitution(&self, node: &ra_syntax::SyntaxNode) -> Option<ra_syntax::SyntaxNode> { 190 fn get_substitution(&self, node: &syntax::SyntaxNode) -> Option<syntax::SyntaxNode> {
197 self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node)) 191 self.get_substitution_inner(node).or_else(|| self.previous.get_substitution(node))
198 } 192 }
199 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> { 193 fn chain_before(self, other: Box<dyn AstTransform<'a> + 'a>) -> Box<dyn AstTransform<'a> + 'a> {