diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/add_missing_impl_members.rs | 24 | ||||
-rw-r--r-- | crates/ra_assists/src/ast_editor.rs | 12 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_text.rs | 8 |
3 files changed, 22 insertions, 22 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() |
diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index c9a5cf8d9..ba816eb65 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs | |||
@@ -85,10 +85,6 @@ impl AstEditor<ast::NamedFieldList> { | |||
85 | self.insert_field(InsertPosition::Last, field) | 85 | self.insert_field(InsertPosition::Last, field) |
86 | } | 86 | } |
87 | 87 | ||
88 | pub fn make_multiline(&mut self) { | ||
89 | self.do_make_multiline() | ||
90 | } | ||
91 | |||
92 | pub fn insert_field( | 88 | pub fn insert_field( |
93 | &mut self, | 89 | &mut self, |
94 | position: InsertPosition<&'_ ast::NamedField>, | 90 | position: InsertPosition<&'_ ast::NamedField>, |
@@ -161,8 +157,12 @@ impl AstEditor<ast::NamedFieldList> { | |||
161 | } | 157 | } |
162 | 158 | ||
163 | impl AstEditor<ast::ItemList> { | 159 | impl AstEditor<ast::ItemList> { |
164 | pub fn make_multiline(&mut self) { | 160 | pub fn append_items<'a>(&mut self, items: impl Iterator<Item = &'a ast::ImplItem>) { |
165 | self.do_make_multiline() | 161 | let n_existing_items = self.ast().impl_items().count(); |
162 | if n_existing_items == 0 { | ||
163 | self.do_make_multiline(); | ||
164 | } | ||
165 | items.for_each(|it| self.append_item(it)); | ||
166 | } | 166 | } |
167 | 167 | ||
168 | pub fn append_item(&mut self, item: &ast::ImplItem) { | 168 | pub fn append_item(&mut self, item: &ast::ImplItem) { |
diff --git a/crates/ra_syntax/src/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs index e648dc082..939f2c02f 100644 --- a/crates/ra_syntax/src/syntax_text.rs +++ b/crates/ra_syntax/src/syntax_text.rs | |||
@@ -38,9 +38,7 @@ impl<'a> SyntaxText<'a> { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | pub fn to_smol_string(&self) -> SmolStr { | 40 | pub fn to_smol_string(&self) -> SmolStr { |
41 | // FIXME: use `self.chunks().collect()` here too once | 41 | self.chunks().collect() |
42 | // https://github.com/matklad/smol_str/pull/12 is merged and published | ||
43 | self.to_string().into() | ||
44 | } | 42 | } |
45 | 43 | ||
46 | pub fn contains(&self, c: char) -> bool { | 44 | pub fn contains(&self, c: char) -> bool { |
@@ -63,6 +61,10 @@ impl<'a> SyntaxText<'a> { | |||
63 | self.range.len() | 61 | self.range.len() |
64 | } | 62 | } |
65 | 63 | ||
64 | pub fn is_empty(&self) -> bool { | ||
65 | self.range.is_empty() | ||
66 | } | ||
67 | |||
66 | /// NB, the offsets here are absolute, and this probably doesn't make sense! | 68 | /// NB, the offsets here are absolute, and this probably doesn't make sense! |
67 | pub fn slice(&self, range: impl ops::RangeBounds<TextUnit>) -> SyntaxText<'a> { | 69 | pub fn slice(&self, range: impl ops::RangeBounds<TextUnit>) -> SyntaxText<'a> { |
68 | let start = match range.start_bound() { | 70 | let start = match range.start_bound() { |