@@ -104,7 +104,6 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
104
104
let ( usages_to_be_processed, record_fields) = module. get_usages_and_record_fields ( ctx) ;
105
105
106
106
let import_paths_to_be_removed = module. resolve_imports ( curr_parent_module, ctx) ;
107
- module. body_items = module. change_visibility ( record_fields) ;
108
107
if module. body_items . len ( ) == 0 {
109
108
return None ;
110
109
}
@@ -114,7 +113,7 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
114
113
"Extract Module" ,
115
114
module. text_range ,
116
115
|builder| {
117
- module. body_items = module . change_visibility ( record_fields) ;
116
+ module. change_visibility ( record_fields) ;
118
117
119
118
let mut body_items: Vec < String > = Vec :: new ( ) ;
120
119
let mut items_to_be_processed: Vec < ast:: Item > = module. body_items . clone ( ) ;
@@ -151,17 +150,11 @@ pub(crate) fn extract_module(acc: &mut Assists, ctx: &AssistContext) -> Option<(
151
150
body = impl_body_def;
152
151
153
152
// Add the import for enum/struct corresponding to given impl block
154
- if let Some ( _) = module. make_use_stmt_of_node_with_super ( self_ty. syntax ( ) ) {
155
- for item in module. use_items {
156
- let mut indented_item = String :: new ( ) ;
157
- format_to ! (
158
- indented_item,
159
- "{}{}" ,
160
- old_item_indent + 1 ,
161
- item. to_string( )
162
- ) ;
163
- body = format ! ( "{}\n \n {}" , indented_item, body) ;
164
- }
153
+ module. make_use_stmt_of_node_with_super ( self_ty. syntax ( ) ) ;
154
+ for item in module. use_items {
155
+ let mut indented_item = String :: new ( ) ;
156
+ format_to ! ( indented_item, "{}{}" , old_item_indent + 1 , item. to_string( ) ) ;
157
+ body = format ! ( "{}\n \n {}" , indented_item, body) ;
165
158
}
166
159
}
167
160
}
@@ -395,9 +388,9 @@ impl Module {
395
388
None
396
389
}
397
390
398
- fn change_visibility ( & self , record_fields : Vec < SyntaxNode > ) -> Vec < ast :: Item > {
399
- let ( body_items , mut replacements, record_field_parents, impls) =
400
- get_replacements_for_visibilty_change ( self . body_items . clone ( ) , false ) ;
391
+ fn change_visibility ( & mut self , record_fields : Vec < SyntaxNode > ) {
392
+ let ( mut replacements, record_field_parents, impls) =
393
+ get_replacements_for_visibilty_change ( & mut self . body_items , false ) ;
401
394
402
395
let mut impl_items = Vec :: new ( ) ;
403
396
for impl_ in impls {
@@ -411,8 +404,8 @@ impl Module {
411
404
impl_items. append ( & mut this_impl_items) ;
412
405
}
413
406
414
- let ( _ , mut impl_item_replacements, _, _) =
415
- get_replacements_for_visibilty_change ( impl_items, true ) ;
407
+ let ( mut impl_item_replacements, _, _) =
408
+ get_replacements_for_visibilty_change ( & mut impl_items, true ) ;
416
409
417
410
replacements. append ( & mut impl_item_replacements) ;
418
411
@@ -429,8 +422,6 @@ impl Module {
429
422
replacements. into_iter ( ) . for_each ( |( vis, syntax) | {
430
423
add_change_vis ( vis, syntax. first_child_or_token ( ) ) ;
431
424
} ) ;
432
-
433
- body_items
434
425
}
435
426
436
427
fn resolve_imports (
@@ -626,20 +617,17 @@ impl Module {
626
617
import_path_to_be_removed
627
618
}
628
619
629
- fn make_use_stmt_of_node_with_super ( & mut self , node_syntax : & SyntaxNode ) -> Option < ast:: Item > {
620
+ fn make_use_stmt_of_node_with_super ( & mut self , node_syntax : & SyntaxNode ) -> ast:: Item {
630
621
let super_path = make:: ext:: ident_path ( "super" ) ;
631
622
let node_path = make:: ext:: ident_path ( & node_syntax. to_string ( ) ) ;
632
623
let use_ = make:: use_ (
633
624
None ,
634
625
make:: use_tree ( make:: join_paths ( vec ! [ super_path, node_path] ) , None , None , false ) ,
635
626
) ;
636
627
637
- if let Some ( item) = ast:: Item :: cast ( use_. syntax ( ) . clone ( ) ) {
638
- self . use_items . insert ( 0 , item. clone ( ) ) ;
639
- return Some ( item) ;
640
- }
641
-
642
- None
628
+ let item = ast:: Item :: from ( use_) ;
629
+ self . use_items . insert ( 0 , item. clone ( ) ) ;
630
+ item
643
631
}
644
632
645
633
fn process_use_stmt_for_import_resolve (
@@ -825,33 +813,30 @@ fn does_source_exists_outside_sel_in_same_mod(
825
813
}
826
814
827
815
fn get_replacements_for_visibilty_change (
828
- items : Vec < ast:: Item > ,
816
+ items : & mut [ ast:: Item ] ,
829
817
is_clone_for_updated : bool ,
830
818
) -> (
831
- Vec < ast:: Item > ,
832
819
Vec < ( Option < ast:: Visibility > , SyntaxNode ) > ,
833
820
Vec < ( Option < ast:: Visibility > , SyntaxNode ) > ,
834
821
Vec < ast:: Impl > ,
835
822
) {
836
823
let mut replacements = Vec :: new ( ) ;
837
824
let mut record_field_parents = Vec :: new ( ) ;
838
825
let mut impls = Vec :: new ( ) ;
839
- let mut body_items = Vec :: new ( ) ;
840
826
841
827
items. into_iter ( ) . for_each ( |item| {
842
- let mut item = item;
828
+ let item = item;
843
829
if !is_clone_for_updated {
844
- item = item. clone_for_update ( ) ;
830
+ * item = item. clone_for_update ( ) ;
845
831
}
846
- body_items. push ( item. clone ( ) ) ;
847
832
//Use stmts are ignored
848
833
match item {
849
834
ast:: Item :: Const ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
850
835
ast:: Item :: Enum ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
851
836
ast:: Item :: ExternCrate ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
852
837
ast:: Item :: Fn ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
853
838
//Associated item's visibility should not be changed
854
- ast:: Item :: Impl ( it) if it. for_token ( ) . is_none ( ) => impls. push ( it) ,
839
+ ast:: Item :: Impl ( it) if it. for_token ( ) . is_none ( ) => impls. push ( it. clone ( ) ) ,
855
840
ast:: Item :: MacroDef ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
856
841
ast:: Item :: Module ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
857
842
ast:: Item :: Static ( it) => replacements. push ( ( it. visibility ( ) , it. syntax ( ) . clone ( ) ) ) ,
@@ -869,7 +854,7 @@ fn get_replacements_for_visibilty_change(
869
854
}
870
855
} ) ;
871
856
872
- ( body_items , replacements, record_field_parents, impls)
857
+ ( replacements, record_field_parents, impls)
873
858
}
874
859
875
860
fn get_use_tree_paths_from_path (
0 commit comments