diff options
author | Ekaterina Babshukova <[email protected]> | 2019-07-10 19:53:44 +0100 |
---|---|---|
committer | Ekaterina Babshukova <[email protected]> | 2019-07-10 20:03:00 +0100 |
commit | 895597d56739c4f181f22e56d8a13a5376d2974a (patch) | |
tree | 0d35c0ddd0c970b39bc0b3bd94b52ea00fe97e52 /crates/ra_assists/src/add_missing_impl_members.rs | |
parent | 82c3fe7d13b67bdec67b53e9adb6f3ec404bf5f0 (diff) |
move whitespace manipulation inside AstEditor
Diffstat (limited to 'crates/ra_assists/src/add_missing_impl_members.rs')
-rw-r--r-- | crates/ra_assists/src/add_missing_impl_members.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs index 7fc8f63b3..6ffdad0b1 100644 --- a/crates/ra_assists/src/add_missing_impl_members.rs +++ b/crates/ra_assists/src/add_missing_impl_members.rs | |||
@@ -78,26 +78,24 @@ fn add_missing_impl_members_inner( | |||
78 | 78 | ||
79 | ctx.add_action(AssistId(assist_id), label, |edit| { | 79 | ctx.add_action(AssistId(assist_id), label, |edit| { |
80 | let n_existing_items = impl_item_list.impl_items().count(); | 80 | let n_existing_items = impl_item_list.impl_items().count(); |
81 | let mut ast_editor = AstEditor::new(impl_item_list); | 81 | let items: Vec<_> = missing_items |
82 | if n_existing_items == 0 { | 82 | .into_iter() |
83 | ast_editor.make_multiline(); | 83 | .map(|it| match it.kind() { |
84 | } | ||
85 | |||
86 | for item in missing_items { | ||
87 | let it = match item.kind() { | ||
88 | ImplItemKind::FnDef(def) => { | 84 | ImplItemKind::FnDef(def) => { |
89 | strip_docstring(ImplItem::cast(add_body(def).syntax()).unwrap()) | 85 | strip_docstring(ImplItem::cast(add_body(def).syntax()).unwrap()) |
90 | } | 86 | } |
91 | _ => strip_docstring(item), | 87 | _ => strip_docstring(it), |
92 | }; | 88 | }) |
93 | ast_editor.append_item(&it) | 89 | .collect(); |
94 | } | 90 | let mut ast_editor = AstEditor::new(impl_item_list); |
91 | |||
92 | ast_editor.append_items(items.iter().map(|it| &**it)); | ||
95 | 93 | ||
96 | let first_new_item = ast_editor.ast().impl_items().nth(n_existing_items).unwrap(); | 94 | let first_new_item = ast_editor.ast().impl_items().nth(n_existing_items).unwrap(); |
97 | let cursor_poisition = first_new_item.syntax().range().start(); | 95 | let cursor_position = first_new_item.syntax().range().start(); |
98 | ast_editor.into_text_edit(edit.text_edit_builder()); | 96 | ast_editor.into_text_edit(edit.text_edit_builder()); |
99 | 97 | ||
100 | edit.set_cursor(cursor_poisition); | 98 | edit.set_cursor(cursor_position); |
101 | }); | 99 | }); |
102 | 100 | ||
103 | ctx.build() | 101 | ctx.build() |