Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/edit_in_place.rs')
| -rw-r--r-- | crates/syntax/src/ast/edit_in_place.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index aa56f10d60..247dfe0b45 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -1,6 +1,6 @@ //! Structural editing for ast. -use std::iter::{empty, successors}; +use std::iter::{empty, once, successors}; use parser::{SyntaxKind, T}; @@ -530,6 +530,25 @@ impl ast::UseTree { Some(()) } } + + /// Wraps the use tree in use tree list with no top level path (if it isn't already). + /// + /// # Examples + /// + /// `foo::bar` -> `{foo::bar}` + /// + /// `{foo::bar}` -> `{foo::bar}` + pub fn wrap_in_tree_list(&self) { + if self.path().is_none() { + return; + } + let subtree = self.clone_subtree().clone_for_update(); + ted::remove_all_iter(self.syntax().children_with_tokens()); + ted::append_child( + self.syntax(), + make::use_tree_list(once(subtree)).clone_for_update().syntax(), + ); + } } impl ast::UseTreeList { |