1
1
use either:: Either ;
2
2
use ide_db:: FxHashMap ;
3
3
use itertools:: Itertools ;
4
- use syntax:: {
5
- ast, ast:: syntax_factory:: SyntaxFactory , syntax_editor:: SyntaxEditor , AstNode , SmolStr ,
6
- SyntaxElement , ToSmolStr ,
7
- } ;
4
+ use syntax:: { ast, ast:: syntax_factory:: SyntaxFactory , AstNode , SmolStr , SyntaxElement , ToSmolStr } ;
8
5
9
6
use crate :: { AssistContext , AssistId , AssistKind , Assists } ;
10
7
@@ -79,10 +76,14 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
79
76
80
77
match fields {
81
78
Either :: Left ( ( sorted, field_list) ) => {
82
- replace ( & mut editor, field_list. fields ( ) , sorted)
79
+ field_list. fields ( ) . zip ( sorted) . for_each ( |( field, sorted_field) | {
80
+ editor. replace ( field. syntax ( ) , sorted_field. syntax ( ) . clone_for_update ( ) ) ;
81
+ } ) ;
83
82
}
84
83
Either :: Right ( ( sorted, field_list) ) => {
85
- replace ( & mut editor, field_list. fields ( ) , sorted)
84
+ field_list. fields ( ) . zip ( sorted) . for_each ( |( field, sorted_field) | {
85
+ editor. replace ( field. syntax ( ) , sorted_field. syntax ( ) . clone_for_update ( ) ) ;
86
+ } ) ;
86
87
}
87
88
}
88
89
@@ -92,16 +93,6 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
92
93
)
93
94
}
94
95
95
- fn replace < T : AstNode + PartialEq > (
96
- editor : & mut SyntaxEditor ,
97
- fields : impl Iterator < Item = T > ,
98
- sorted_fields : impl IntoIterator < Item = T > ,
99
- ) {
100
- fields. zip ( sorted_fields) . for_each ( |( field, sorted_field) | {
101
- editor. replace ( field. syntax ( ) , sorted_field. syntax ( ) . clone_for_update ( ) )
102
- } ) ;
103
- }
104
-
105
96
fn compute_fields_ranks (
106
97
path : & ast:: Path ,
107
98
ctx : & AssistContext < ' _ > ,
0 commit comments