cleanup editor

This commit is contained in:
Aleksey Kladov 2019-09-30 10:08:28 +03:00
parent 05ca252fb5
commit 4acadbdca6
2 changed files with 11 additions and 5 deletions

View File

@ -75,10 +75,13 @@ fn add_missing_impl_members_inner(
ctx.add_action(AssistId(assist_id), label, |edit| { ctx.add_action(AssistId(assist_id), label, |edit| {
let n_existing_items = impl_item_list.impl_items().count(); let n_existing_items = impl_item_list.impl_items().count();
let items = missing_items.into_iter().map(|it| match it { let items = missing_items
ast::ImplItem::FnDef(def) => edit::strip_attrs_and_docs(add_body(def).into()), .into_iter()
_ => edit::strip_attrs_and_docs(it), .map(|it| match it {
}); ast::ImplItem::FnDef(def) => ast::ImplItem::FnDef(add_body(def)),
_ => it,
})
.map(|it| edit::strip_attrs_and_docs(&it));
let new_impl_item_list = impl_item_list.append_items(items); let new_impl_item_list = impl_item_list.append_items(items);
let cursor_position = { let cursor_position = {
let first_new_item = new_impl_item_list.impl_items().nth(n_existing_items).unwrap(); let first_new_item = new_impl_item_list.impl_items().nth(n_existing_items).unwrap();

View File

@ -187,6 +187,7 @@ impl ast::RecordFieldList {
} }
impl ast::TypeParam { impl ast::TypeParam {
#[must_use]
pub fn remove_bounds(&self) -> ast::TypeParam { pub fn remove_bounds(&self) -> ast::TypeParam {
let colon = match self.colon_token() { let colon = match self.colon_token() {
Some(it) => it, Some(it) => it,
@ -200,7 +201,8 @@ impl ast::TypeParam {
} }
} }
pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: N) -> N { #[must_use]
pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N {
N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()
} }
@ -217,6 +219,7 @@ fn strip_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode {
node node
} }
#[must_use]
pub fn replace_descendants<N: AstNode, D: AstNode>( pub fn replace_descendants<N: AstNode, D: AstNode>(
parent: &N, parent: &N,
replacement_map: impl Iterator<Item = (D, D)>, replacement_map: impl Iterator<Item = (D, D)>,