From 15fc643e05bf8273e378243edbfb3be7aea7ce11 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 10 Jan 2020 18:26:18 +0100 Subject: Fix ordering problem between qualifying paths and substituting params --- crates/ra_syntax/src/ast/edit.rs | 8 ++++---- crates/ra_syntax/src/ast/make.rs | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'crates/ra_syntax/src/ast') 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 { let map = replacement_map .map(|(from, to)| (from.syntax().clone().into(), to.syntax().clone().into())) - .collect::>(); - let new_syntax = algo::replace_descendants(parent.syntax(), &map); + .collect::>(); + let new_syntax = algo::replace_descendants(parent.syntax(), &|n| map.get(n).cloned()); N::cast(new_syntax).unwrap() } @@ -292,7 +292,7 @@ impl IndentLevel { ) }) .collect(); - algo::replace_descendants(&node, &replacements) + algo::replace_descendants(&node, &|n| replacements.get(n).cloned()) } pub fn decrease_indent(self, node: N) -> N { @@ -320,7 +320,7 @@ impl IndentLevel { ) }) .collect(); - algo::replace_descendants(&node, &replacements) + algo::replace_descendants(&node, &|n| replacements.get(n).cloned()) } } 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 @@ //! of smaller pieces. use itertools::Itertools; -use crate::{ast, AstNode, SourceFile}; +use crate::{algo, ast, AstNode, SourceFile}; pub fn name(text: &str) -> ast::Name { ast_from_text(&format!("mod {};", text)) @@ -23,7 +23,14 @@ fn path_from_text(text: &str) -> ast::Path { } pub fn path_with_type_arg_list(path: ast::Path, args: Option) -> ast::Path { if let Some(args) = args { - ast_from_text(&format!("const X: {}{}", path.syntax(), args.syntax())) + let syntax = path.syntax(); + // FIXME: remove existing type args + let new_syntax = algo::insert_children( + syntax, + crate::algo::InsertPosition::Last, + &mut Some(args).into_iter().map(|n| n.syntax().clone().into()), + ); + ast::Path::cast(new_syntax).unwrap() } else { path } -- cgit v1.2.3