Skip to content

Commit fbf2dfa

Browse files
committed
migrate generate_module_def to use SyntaxFactory
1 parent deb4b6f commit fbf2dfa

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

crates/ide-assists/src/handlers/extract_module.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn generate_module_def(
188188
parent_impl: &Option<ast::Impl>,
189189
Module { name, body_items, use_items }: &Module,
190190
) -> ast::Module {
191+
let make = SyntaxFactory::without_mappings();
191192
let items: Vec<_> = if let Some(impl_) = parent_impl.as_ref()
192193
&& let Some(self_ty) = impl_.self_ty()
193194
{
@@ -199,12 +200,12 @@ fn generate_module_def(
199200
.collect_vec();
200201
let impl_detached = ast::Impl::cast(impl_.syntax().clone_subtree()).unwrap();
201202
let mut editor = SyntaxEditor::new(impl_detached.syntax().clone());
202-
let make = SyntaxFactory::with_mappings();
203-
let assoc_item_list = make.assoc_item_list(assoc_items);
203+
let make_editor = SyntaxFactory::with_mappings();
204+
let assoc_item_list = make_editor.assoc_item_list(assoc_items);
204205
if let Some(existing_list) = impl_detached.assoc_item_list() {
205206
editor.replace(existing_list.syntax(), assoc_item_list.syntax());
206207
}
207-
editor.add_mappings(make.finish_with_mappings());
208+
editor.add_mappings(make_editor.finish_with_mappings());
208209
let new_impl_node = editor.finish().new_root().clone();
209210
let impl_ = ast::Impl::cast(new_impl_node).unwrap().reset_indent();
210211
// Add the import for enum/struct corresponding to given impl block
@@ -218,10 +219,10 @@ fn generate_module_def(
218219
};
219220

220221
let items = items.into_iter().map(|it| it.reset_indent().indent(IndentLevel(1))).collect_vec();
221-
let module_body = make::item_list(Some(items));
222+
let module_body = make.item_list(items);
222223

223-
let module_name = make::name(name);
224-
make::mod_(module_name, Some(module_body))
224+
let module_name = make.name(name);
225+
make.mod_(module_name, Some(module_body))
225226
}
226227

227228
fn make_use_stmt_of_node_with_super(node_syntax: &SyntaxNode) -> ast::Item {

crates/syntax/src/ast/syntax_factory/constructors.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,10 +1785,7 @@ impl SyntaxFactory {
17851785
make::assoc_item_list(None).clone_for_update()
17861786
}
17871787

1788-
pub fn item_list(
1789-
&self,
1790-
items: impl IntoIterator<Item = ast::Item>,
1791-
) -> ast::ItemList {
1788+
pub fn item_list(&self, items: impl IntoIterator<Item = ast::Item>) -> ast::ItemList {
17921789
let (items, input) = iterator_input(items);
17931790
let items_vec: Vec<_> = items.into_iter().collect();
17941791
let ast = make::item_list(Some(items_vec)).clone_for_update();
@@ -1802,21 +1799,14 @@ impl SyntaxFactory {
18021799
ast
18031800
}
18041801

1805-
pub fn mod_(
1806-
&self,
1807-
name: ast::Name,
1808-
body: Option<ast::ItemList>,
1809-
) -> ast::Module {
1802+
pub fn mod_(&self, name: ast::Name, body: Option<ast::ItemList>) -> ast::Module {
18101803
let ast = make::mod_(name.clone(), body.clone()).clone_for_update();
18111804

18121805
if let Some(mut mapping) = self.mappings() {
18131806
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
18141807
builder.map_node(name.syntax().clone(), ast.name().unwrap().syntax().clone());
18151808
if let Some(body) = body {
1816-
builder.map_node(
1817-
body.syntax().clone(),
1818-
ast.item_list().unwrap().syntax().clone(),
1819-
);
1809+
builder.map_node(body.syntax().clone(), ast.item_list().unwrap().syntax().clone());
18201810
}
18211811
builder.finish(&mut mapping);
18221812
}

0 commit comments

Comments
 (0)