From ea0c124219da33462b9d0be93f7abe0478cc7af2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 5 Mar 2020 19:03:14 +0100 Subject: Rerail split_import API onto AST The code is more verbose and less efficient now, but should be reusable in add_import context as well --- crates/ra_syntax/src/ast/edit.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/ra_syntax/src/ast/edit.rs') diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 1858e2b6c..e4cdccdb4 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -259,6 +259,24 @@ impl ast::UseItem { } } +impl ast::UseTree { + #[must_use] + pub fn with_path(&self, path: ast::Path) -> ast::UseTree { + if let Some(old) = self.path() { + return replace_descendants(self, iter::once((old, path))); + } + self.clone() + } + + #[must_use] + pub fn with_use_tree_list(&self, use_tree_list: ast::UseTreeList) -> ast::UseTree { + if let Some(old) = self.use_tree_list() { + return replace_descendants(self, iter::once((old, use_tree_list))); + } + self.clone() + } +} + #[must_use] pub fn strip_attrs_and_docs(node: &N) -> N { N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() -- cgit v1.2.3