aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/edit.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-05 18:03:14 +0000
committerAleksey Kladov <[email protected]>2020-03-06 13:08:43 +0000
commitea0c124219da33462b9d0be93f7abe0478cc7af2 (patch)
tree18d0c7a15da29214a6387f0880135fdf7f738df1 /crates/ra_syntax/src/ast/edit.rs
parentd75577fcee79aac06bdddb01fde431f26432c36c (diff)
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
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs18
1 files changed, 18 insertions, 0 deletions
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 {
259 } 259 }
260} 260}
261 261
262impl ast::UseTree {
263 #[must_use]
264 pub fn with_path(&self, path: ast::Path) -> ast::UseTree {
265 if let Some(old) = self.path() {
266 return replace_descendants(self, iter::once((old, path)));
267 }
268 self.clone()
269 }
270
271 #[must_use]
272 pub fn with_use_tree_list(&self, use_tree_list: ast::UseTreeList) -> ast::UseTree {
273 if let Some(old) = self.use_tree_list() {
274 return replace_descendants(self, iter::once((old, use_tree_list)));
275 }
276 self.clone()
277 }
278}
279
262#[must_use] 280#[must_use]
263pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N { 281pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
264 N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() 282 N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()