From 381ace587eb1629019d5d07eba571ddc9d27cc08 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 5 Mar 2020 18:38:52 +0100 Subject: [PATCH] Add with_use_tree --- crates/ra_syntax/src/ast/edit.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index d2630e9e99c..1858e2b6c17 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -249,6 +249,16 @@ impl ast::PathSegment { } } +impl ast::UseItem { + #[must_use] + pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { + if let Some(old) = self.use_tree() { + return replace_descendants(self, iter::once((old, use_tree))); + } + self.clone() + } +} + #[must_use] pub fn strip_attrs_and_docs(node: &N) -> N { N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()