|
1 | 1 | use ide_db::assists::AssistId;
|
2 | 2 | use syntax::{
|
3 | 3 | AstNode, T,
|
4 |
| - ast::{self, make}, |
5 |
| - ted, |
| 4 | + ast::{self, syntax_factory::SyntaxFactory}, |
6 | 5 | };
|
7 | 6 |
|
8 | 7 | use crate::{AssistContext, Assists};
|
@@ -37,8 +36,7 @@ pub(crate) fn toggle_macro_delimiter(acc: &mut Assists, ctx: &AssistContext<'_>)
|
37 | 36 | RCur,
|
38 | 37 | }
|
39 | 38 |
|
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>()?; |
42 | 40 |
|
43 | 41 | let cursor_offset = ctx.offset();
|
44 | 42 | let semicolon = makro.semicolon_token();
|
@@ -71,24 +69,28 @@ pub(crate) fn toggle_macro_delimiter(acc: &mut Assists, ctx: &AssistContext<'_>)
|
71 | 69 | },
|
72 | 70 | token_tree.syntax().text_range(),
|
73 | 71 | |builder| {
|
| 72 | + let make = SyntaxFactory::with_mappings(); |
| 73 | + let mut editor = builder.make_editor(makro.syntax()); |
| 74 | + |
74 | 75 | match token {
|
75 | 76 | 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!['}'])); |
78 | 79 | if let Some(sc) = semicolon {
|
79 |
| - ted::remove(sc); |
| 80 | + editor.delete(sc); |
80 | 81 | }
|
81 | 82 | }
|
82 | 83 | 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![')'])); |
85 | 86 | }
|
86 | 87 | 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![']'])); |
89 | 90 | }
|
90 | 91 | }
|
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); |
92 | 94 | },
|
93 | 95 | )
|
94 | 96 | }
|
|
0 commit comments