mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Add edit utility for adding an associated item list to a impl def
This commit is contained in:
parent
82dc4af5de
commit
4362297a0b
1 changed files with 16 additions and 0 deletions
|
@ -93,6 +93,22 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::Impl {
|
||||
#[must_use]
|
||||
pub fn with_items(&self, items: ast::AssocItemList) -> ast::Impl {
|
||||
let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
|
||||
if let Some(old_items) = self.assoc_item_list() {
|
||||
let to_replace: SyntaxElement = old_items.syntax().clone().into();
|
||||
to_insert.push(items.syntax().clone().into());
|
||||
self.replace_children(single_node(to_replace), to_insert)
|
||||
} else {
|
||||
to_insert.push(make::tokens::single_space().into());
|
||||
to_insert.push(items.syntax().clone().into());
|
||||
self.insert_children(InsertPosition::Last, to_insert)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::AssocItemList {
|
||||
#[must_use]
|
||||
pub fn append_items(
|
||||
|
|
Loading…
Reference in a new issue