Skip to content

Commit 3af0f4f

Browse files
committed
Migrate toggle_macro_delimiter assist to SyntaxEditor
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
1 parent cb52f4c commit 3af0f4f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use ide_db::assists::AssistId;
22
use syntax::{
33
AstNode, T,
4-
ast::{self, make},
5-
ted,
4+
ast::{self, syntax_factory::SyntaxFactory},
65
};
76

87
use crate::{AssistContext, Assists};
@@ -37,8 +36,7 @@ pub(crate) fn toggle_macro_delimiter(acc: &mut Assists, ctx: &AssistContext<'_>)
3736
RCur,
3837
}
3938

40-
let makro = ctx.find_node_at_offset::<ast::MacroCall>()?.clone_for_update();
41-
let makro_text_range = makro.syntax().text_range();
39+
let makro = ctx.find_node_at_offset::<ast::MacroCall>()?;
4240

4341
let cursor_offset = ctx.offset();
4442
let semicolon = makro.semicolon_token();
@@ -71,24 +69,28 @@ pub(crate) fn toggle_macro_delimiter(acc: &mut Assists, ctx: &AssistContext<'_>)
7169
},
7270
token_tree.syntax().text_range(),
7371
|builder| {
72+
let make = SyntaxFactory::with_mappings();
73+
let mut editor = builder.make_editor(makro.syntax());
74+
7475
match token {
7576
MacroDelims::LPar | MacroDelims::RPar => {
76-
ted::replace(ltoken, make::token(T!['{']));
77-
ted::replace(rtoken, make::token(T!['}']));
77+
editor.replace(ltoken, make.token(T!['{']));
78+
editor.replace(rtoken, make.token(T!['}']));
7879
if let Some(sc) = semicolon {
79-
ted::remove(sc);
80+
editor.delete(sc);
8081
}
8182
}
8283
MacroDelims::LBra | MacroDelims::RBra => {
83-
ted::replace(ltoken, make::token(T!['(']));
84-
ted::replace(rtoken, make::token(T![')']));
84+
editor.replace(ltoken, make.token(T!['(']));
85+
editor.replace(rtoken, make.token(T![')']));
8586
}
8687
MacroDelims::LCur | MacroDelims::RCur => {
87-
ted::replace(ltoken, make::token(T!['[']));
88-
ted::replace(rtoken, make::token(T![']']));
88+
editor.replace(ltoken, make.token(T!['[']));
89+
editor.replace(rtoken, make.token(T![']']));
8990
}
9091
}
91-
builder.replace(makro_text_range, makro.syntax().text());
92+
editor.add_mappings(make.finish_with_mappings());
93+
builder.add_file_edits(ctx.vfs_file_id(), editor);
9294
},
9395
)
9496
}

0 commit comments

Comments
 (0)