Skip to content

Commit 05ca3f1

Browse files
authored
Merge pull request #20211 from Hmikihiro/migrate-convert_named_struct
Migrate `convert_named_struct_to_tuple_struct` assist to use 'SyntaxEditor'
2 parents 64551a5 + 5a410c3 commit 05ca3f1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use itertools::Itertools;
44
use syntax::{
55
SyntaxKind,
66
ast::{self, AstNode, HasAttrs, HasGenericParams, HasVisibility},
7-
match_ast, ted,
7+
match_ast,
8+
syntax_editor::{Position, SyntaxEditor},
89
};
910

1011
use crate::{AssistContext, AssistId, Assists, assist_context::SourceChangeBuilder};
@@ -97,11 +98,14 @@ fn edit_struct_def(
9798
// Note that we don't need to consider macro files in this function because this is
9899
// currently not triggered for struct definitions inside macro calls.
99100
let tuple_fields = record_fields.fields().filter_map(|f| {
100-
let field = ast::make::tuple_field(f.visibility(), f.ty()?).clone_for_update();
101-
ted::insert_all(
102-
ted::Position::first_child_of(field.syntax()),
101+
let field = ast::make::tuple_field(f.visibility(), f.ty()?);
102+
let mut editor = SyntaxEditor::new(field.syntax().clone());
103+
editor.insert_all(
104+
Position::first_child_of(field.syntax()),
103105
f.attrs().map(|attr| attr.syntax().clone_subtree().clone_for_update().into()).collect(),
104106
);
107+
let field_syntax = editor.finish().new_root().clone();
108+
let field = ast::TupleField::cast(field_syntax)?;
105109
Some(field)
106110
});
107111
let tuple_fields = ast::make::tuple_field_list(tuple_fields);
@@ -1086,8 +1090,7 @@ pub struct $0Foo {
10861090
}
10871091
"#,
10881092
r#"
1089-
pub struct Foo(#[my_custom_attr]
1090-
u32);
1093+
pub struct Foo(#[my_custom_attr]u32);
10911094
"#,
10921095
);
10931096
}

0 commit comments

Comments
 (0)