diff options
author | Aleksey Kladov <[email protected]> | 2020-10-06 15:19:18 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-10-06 15:19:18 +0100 |
commit | 2090b534fc249a493823bb8e9039c0123aa0b90e (patch) | |
tree | f6f8469d5e4bbd37655aabb75edf32a392b0ed0c /crates/assists/src/ast_transform.rs | |
parent | 9507a01e9e76afca9f6f8d460089fc199703b820 (diff) |
Move ModPath->ast::Path function to IDE layer
closes #6092
Diffstat (limited to 'crates/assists/src/ast_transform.rs')
-rw-r--r-- | crates/assists/src/ast_transform.rs | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/crates/assists/src/ast_transform.rs b/crates/assists/src/ast_transform.rs index 4307e0191..ac72f3f02 100644 --- a/crates/assists/src/ast_transform.rs +++ b/crates/assists/src/ast_transform.rs | |||
@@ -1,13 +1,14 @@ | |||
1 | //! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined. | 1 | //! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined. |
2 | use rustc_hash::FxHashMap; | ||
3 | |||
4 | use hir::{HirDisplay, PathResolution, SemanticsScope}; | 2 | use hir::{HirDisplay, PathResolution, SemanticsScope}; |
3 | use rustc_hash::FxHashMap; | ||
5 | use syntax::{ | 4 | use syntax::{ |
6 | algo::SyntaxRewriter, | 5 | algo::SyntaxRewriter, |
7 | ast::{self, AstNode}, | 6 | ast::{self, AstNode}, |
8 | SyntaxNode, | 7 | SyntaxNode, |
9 | }; | 8 | }; |
10 | 9 | ||
10 | use crate::utils::mod_path_to_ast; | ||
11 | |||
11 | pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N { | 12 | pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N { |
12 | SyntaxRewriter::from_fn(|element| match element { | 13 | SyntaxRewriter::from_fn(|element| match element { |
13 | syntax::SyntaxElement::Node(n) => { | 14 | syntax::SyntaxElement::Node(n) => { |
@@ -189,7 +190,7 @@ impl<'a> AstTransform<'a> for QualifyPaths<'a> { | |||
189 | match resolution { | 190 | match resolution { |
190 | PathResolution::Def(def) => { | 191 | PathResolution::Def(def) => { |
191 | let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?; | 192 | let found_path = from.find_use_path(self.source_scope.db.upcast(), def)?; |
192 | let mut path = path_to_ast(found_path); | 193 | let mut path = mod_path_to_ast(&found_path); |
193 | 194 | ||
194 | let type_args = p | 195 | let type_args = p |
195 | .segment() | 196 | .segment() |
@@ -210,13 +211,3 @@ impl<'a> AstTransform<'a> for QualifyPaths<'a> { | |||
210 | } | 211 | } |
211 | } | 212 | } |
212 | } | 213 | } |
213 | |||
214 | pub(crate) fn path_to_ast(path: hir::ModPath) -> ast::Path { | ||
215 | let parse = ast::SourceFile::parse(&path.to_string()); | ||
216 | parse | ||
217 | .tree() | ||
218 | .syntax() | ||
219 | .descendants() | ||
220 | .find_map(ast::Path::cast) | ||
221 | .unwrap_or_else(|| panic!("failed to parse path {:?}, `{}`", path, path)) | ||
222 | } | ||