aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs8
-rw-r--r--crates/ra_syntax/src/ast/make.rs11
2 files changed, 13 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index ae5d63927..b736098ac 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -236,8 +236,8 @@ pub fn replace_descendants<N: AstNode, D: AstNode>(
236) -> N { 236) -> N {
237 let map = replacement_map 237 let map = replacement_map
238 .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into())) 238 .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into()))
239 .collect::<FxHashMap<_, _>>(); 239 .collect::<FxHashMap<SyntaxElement, _>>();
240 let new_syntax = algo::replace_descendants(parent.syntax(), &map); 240 let new_syntax = algo::replace_descendants(parent.syntax(), &|n| map.get(n).cloned());
241 N::cast(new_syntax).unwrap() 241 N::cast(new_syntax).unwrap()
242} 242}
243 243
@@ -292,7 +292,7 @@ impl IndentLevel {
292 ) 292 )
293 }) 293 })
294 .collect(); 294 .collect();
295 algo::replace_descendants(&node, &replacements) 295 algo::replace_descendants(&node, &|n| replacements.get(n).cloned())
296 } 296 }
297 297
298 pub fn decrease_indent<N: AstNode>(self, node: N) -> N { 298 pub fn decrease_indent<N: AstNode>(self, node: N) -> N {
@@ -320,7 +320,7 @@ impl IndentLevel {
320 ) 320 )
321 }) 321 })
322 .collect(); 322 .collect();
323 algo::replace_descendants(&node, &replacements) 323 algo::replace_descendants(&node, &|n| replacements.get(n).cloned())
324 } 324 }
325} 325}
326 326
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 68d64a0cc..9781b748f 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -2,7 +2,7 @@
2//! of smaller pieces. 2//! of smaller pieces.
3use itertools::Itertools; 3use itertools::Itertools;
4 4
5use crate::{ast, AstNode, SourceFile}; 5use crate::{algo, ast, AstNode, SourceFile};
6 6
7pub fn name(text: &str) -> ast::Name { 7pub fn name(text: &str) -> ast::Name {
8 ast_from_text(&format!("mod {};", text)) 8 ast_from_text(&format!("mod {};", text))
@@ -23,7 +23,14 @@ fn path_from_text(text: &str) -> ast::Path {
23} 23}
24pub fn path_with_type_arg_list(path: ast::Path, args: Option<ast::TypeArgList>) -> ast::Path { 24pub fn path_with_type_arg_list(path: ast::Path, args: Option<ast::TypeArgList>) -> ast::Path {
25 if let Some(args) = args { 25 if let Some(args) = args {
26 ast_from_text(&format!("const X: {}{}", path.syntax(), args.syntax())) 26 let syntax = path.syntax();
27 // FIXME: remove existing type args
28 let new_syntax = algo::insert_children(
29 syntax,
30 crate::algo::InsertPosition::Last,
31 &mut Some(args).into_iter().map(|n| n.syntax().clone().into()),
32 );
33 ast::Path::cast(new_syntax).unwrap()
27 } else { 34 } else {
28 path 35 path
29 } 36 }