@@ -462,7 +462,7 @@ impl Module {
462
462
}
463
463
}
464
464
465
- let def_in_mod_and_out_sel =
465
+ let ( def_in_mod , def_out_sel ) =
466
466
check_def_in_mod_and_out_sel ( def, ctx, curr_parent_module, selection_range, file_id) ;
467
467
468
468
// Find use stmt that use def in current file
@@ -493,9 +493,9 @@ impl Module {
493
493
//If not, insert a use stmt with super and the given nameref
494
494
match self . process_use_stmt_for_import_resolve ( use_stmt, node_syntax) {
495
495
Some ( ( use_tree_str, _) ) => use_tree_str_opt = Some ( use_tree_str) ,
496
- None if def_in_mod_and_out_sel => {
496
+ None if def_in_mod && def_out_sel => {
497
497
//Considered only after use_stmt is not present
498
- //def_in_mod_and_out_sel | exists_outside_sel(exists_inside_sel =
498
+ //def_in_mod && def_out_sel | exists_outside_sel(exists_inside_sel =
499
499
//true for all cases)
500
500
// false | false -> Do nothing
501
501
// false | true -> If source is in selection -> nothing to do, If source is outside
@@ -516,7 +516,7 @@ impl Module {
516
516
import_path_to_be_removed = Some ( text_range) ;
517
517
}
518
518
519
- if def_in_mod_and_out_sel {
519
+ if def_in_mod && def_out_sel {
520
520
if let Some ( first_path_in_use_tree) = use_tree_str. last ( ) {
521
521
let first_path_in_use_tree_str = first_path_in_use_tree. to_string ( ) ;
522
522
if !first_path_in_use_tree_str. contains ( "super" )
@@ -529,7 +529,7 @@ impl Module {
529
529
}
530
530
531
531
use_tree_str_opt = Some ( use_tree_str) ;
532
- } else if def_in_mod_and_out_sel {
532
+ } else if def_in_mod && def_out_sel {
533
533
self . make_use_stmt_of_node_with_super ( node_syntax) ;
534
534
}
535
535
}
@@ -538,7 +538,7 @@ impl Module {
538
538
let mut use_tree_str = use_tree_str;
539
539
use_tree_str. reverse ( ) ;
540
540
541
- if exists_outside_sel || !exists_inside_sel || !def_in_mod_and_out_sel {
541
+ if exists_outside_sel || !exists_inside_sel || !def_in_mod || !def_out_sel {
542
542
if let Some ( first_path_in_use_tree) = use_tree_str. first ( ) {
543
543
if first_path_in_use_tree. to_string ( ) . contains ( "super" ) {
544
544
use_tree_str. insert ( 0 , make:: ext:: ident_path ( "super" ) ) ;
@@ -549,7 +549,10 @@ impl Module {
549
549
let use_ =
550
550
make:: use_ ( None , make:: use_tree ( make:: join_paths ( use_tree_str) , None , None , false ) ) ;
551
551
let item = ast:: Item :: from ( use_) ;
552
- self . use_items . insert ( 0 , item) ;
552
+
553
+ if def_out_sel {
554
+ self . use_items . insert ( 0 , item. clone ( ) ) ;
555
+ }
553
556
}
554
557
555
558
import_path_to_be_removed
@@ -624,7 +627,7 @@ fn check_def_in_mod_and_out_sel(
624
627
curr_parent_module : & Option < ast:: Module > ,
625
628
selection_range : TextRange ,
626
629
curr_file_id : FileId ,
627
- ) -> bool {
630
+ ) -> ( bool , bool ) {
628
631
macro_rules! check_item {
629
632
( $x: ident) => {
630
633
if let Some ( source) = $x. source( ctx. db( ) ) {
@@ -634,9 +637,8 @@ fn check_def_in_mod_and_out_sel(
634
637
source. file_id. original_file( ctx. db( ) ) == curr_file_id
635
638
} ;
636
639
637
- if have_same_parent {
638
- return !selection_range. contains_range( source. value. syntax( ) . text_range( ) ) ;
639
- }
640
+ let in_sel = !selection_range. contains_range( source. value. syntax( ) . text_range( ) ) ;
641
+ return ( have_same_parent, in_sel) ;
640
642
}
641
643
} ;
642
644
}
@@ -653,9 +655,12 @@ fn check_def_in_mod_and_out_sel(
653
655
654
656
if have_same_parent {
655
657
if let ModuleSource :: Module ( module_) = source. value {
656
- return !selection_range. contains_range ( module_. syntax ( ) . text_range ( ) ) ;
658
+ let in_sel = !selection_range. contains_range ( module_. syntax ( ) . text_range ( ) ) ;
659
+ return ( have_same_parent, in_sel) ;
657
660
}
658
661
}
662
+
663
+ return ( have_same_parent, false ) ;
659
664
}
660
665
Definition :: Function ( x) => check_item ! ( x) ,
661
666
Definition :: Adt ( x) => check_item ! ( x) ,
@@ -667,7 +672,7 @@ fn check_def_in_mod_and_out_sel(
667
672
_ => { }
668
673
}
669
674
670
- false
675
+ ( false , false )
671
676
}
672
677
673
678
fn get_replacements_for_visibility_change (
0 commit comments