@@ -6,8 +6,8 @@ use ide_db::imports::{
6
6
use itertools:: Itertools ;
7
7
use syntax:: {
8
8
algo:: neighbor,
9
- ast:: { self , edit_in_place:: Removable } ,
10
- match_ast, ted , AstNode , SyntaxElement , SyntaxNode ,
9
+ ast:: { self , edit_in_place:: Removable , syntax_factory :: SyntaxFactory } ,
10
+ match_ast, AstNode , SyntaxElement , SyntaxNode ,
11
11
} ;
12
12
13
13
use crate :: {
@@ -68,11 +68,19 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
68
68
( selection_range, edits?)
69
69
} ;
70
70
71
+ // FIXME: Is this the best to get a `SyntaxNode` object? We need one for `SourceChangeBuilder::make_editor`.
72
+ let parent_node = match ctx. covering_element ( ) {
73
+ SyntaxElement :: Node ( n) => n,
74
+ SyntaxElement :: Token ( t) => t. parent ( ) ?,
75
+ } ;
76
+ let make = SyntaxFactory :: new ( ) ;
77
+
71
78
acc. add (
72
79
AssistId ( "merge_imports" , AssistKind :: RefactorRewrite ) ,
73
80
"Merge imports" ,
74
81
target,
75
82
|builder| {
83
+ let mut editor = builder. make_editor ( & parent_node) ;
76
84
let edits_mut: Vec < Edit > = edits
77
85
. into_iter ( )
78
86
. map ( |it| match it {
@@ -85,7 +93,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
85
93
match edit {
86
94
Remove ( it) => it. as_ref ( ) . either ( Removable :: remove, Removable :: remove) ,
87
95
Replace ( old, new) => {
88
- ted :: replace ( old, & new) ;
96
+ editor . replace ( old, & new) ;
89
97
90
98
// If there's a selection and we're replacing a use tree in a tree list,
91
99
// normalize the parent use tree if it only contains the merged subtree.
@@ -109,12 +117,14 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
109
117
} ) ;
110
118
if let Some ( ( old_tree, new_tree) ) = normalized_use_tree {
111
119
cov_mark:: hit!( replace_parent_with_normalized_use_tree) ;
112
- ted :: replace ( old_tree. syntax ( ) , new_tree. syntax ( ) ) ;
120
+ editor . replace ( old_tree. syntax ( ) , new_tree. syntax ( ) ) ;
113
121
}
114
122
}
115
123
}
116
124
}
117
125
}
126
+ editor. add_mappings ( make. finish_with_mappings ( ) ) ;
127
+ builder. add_file_edits ( ctx. file_id ( ) , editor) ;
118
128
} ,
119
129
)
120
130
}
0 commit comments