@@ -35,9 +35,9 @@ fn trimmed_text_range(source_file: &SourceFile, initial_range: TextRange) -> Tex
3535 trimmed_range
3636}
3737
38- // Assist: promote_mod_file
38+ // Assist: move_to_mod_rs
3939//
40- // Moves inline module's contents to a separate file .
40+ // Moves xxx.rs to xxx/mod.rs .
4141//
4242// ```
4343// //- /main.rs
@@ -49,13 +49,18 @@ fn trimmed_text_range(source_file: &SourceFile, initial_range: TextRange) -> Tex
4949// ```
5050// fn t() {}
5151// ```
52- pub ( crate ) fn promote_mod_file ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
52+ pub ( crate ) fn move_to_mod_rs ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
5353 let source_file = ctx. find_node_at_offset :: < ast:: SourceFile > ( ) ?;
5454 let module = ctx. sema . to_module_def ( ctx. frange . file_id ) ?;
5555 // Enable this assist if the user select all "meaningful" content in the source file
5656 let trimmed_selected_range = trimmed_text_range ( & source_file, ctx. frange . range ) ;
5757 let trimmed_file_range = trimmed_text_range ( & source_file, source_file. syntax ( ) . text_range ( ) ) ;
58- if module. is_mod_rs ( ctx. db ( ) ) || trimmed_selected_range != trimmed_file_range {
58+ if module. is_mod_rs ( ctx. db ( ) ) {
59+ cov_mark:: hit!( already_mod_rs) ;
60+ return None ;
61+ }
62+ if trimmed_selected_range != trimmed_file_range {
63+ cov_mark:: hit!( not_all_selected) ;
5964 return None ;
6065 }
6166
@@ -67,7 +72,7 @@ pub(crate) fn promote_mod_file(acc: &mut Assists, ctx: &AssistContext) -> Option
6772 let path = format ! ( "./{}/mod.rs" , module_name) ;
6873 let dst = AnchoredPathBuf { anchor : ctx. frange . file_id , path } ;
6974 acc. add (
70- AssistId ( "promote_mod_file " , AssistKind :: Refactor ) ,
75+ AssistId ( "move_to_mod_rs " , AssistKind :: Refactor ) ,
7176 format ! ( "Turn {}.rs to {}/mod.rs" , module_name, module_name) ,
7277 target,
7378 |builder| {
@@ -85,7 +90,7 @@ mod tests {
8590 #[ test]
8691 fn trivial ( ) {
8792 check_assist (
88- promote_mod_file ,
93+ move_to_mod_rs ,
8994 r#"
9095//- /main.rs
9196mod a;
@@ -101,17 +106,19 @@ fn t() {}
101106
102107 #[ test]
103108 fn must_select_all_file ( ) {
109+ cov_mark:: check!( not_all_selected) ;
104110 check_assist_not_applicable (
105- promote_mod_file ,
111+ move_to_mod_rs ,
106112 r#"
107113//- /main.rs
108114mod a;
109115//- /a.rs
110116fn t() {}$0
111117"# ,
112118 ) ;
119+ cov_mark:: check!( not_all_selected) ;
113120 check_assist_not_applicable (
114- promote_mod_file ,
121+ move_to_mod_rs ,
115122 r#"
116123//- /main.rs
117124mod a;
@@ -123,28 +130,29 @@ $0fn$0 t() {}
123130
124131 #[ test]
125132 fn cannot_promote_mod_rs ( ) {
133+ cov_mark:: check!( already_mod_rs) ;
126134 check_assist_not_applicable (
127- promote_mod_file ,
135+ move_to_mod_rs ,
128136 r#"//- /main.rs
129137mod a;
130138//- /a/mod.rs
131- $0fn t() {}
139+ $0fn t() {}$0
132140"# ,
133141 ) ;
134142 }
135143
136144 #[ test]
137145 fn cannot_promote_main_and_lib_rs ( ) {
138146 check_assist_not_applicable (
139- promote_mod_file ,
147+ move_to_mod_rs ,
140148 r#"//- /main.rs
141- $0fn t() {}
149+ $0fn t() {}$0
142150"# ,
143151 ) ;
144152 check_assist_not_applicable (
145- promote_mod_file ,
153+ move_to_mod_rs ,
146154 r#"//- /lib.rs
147- $0fn t() {}
155+ $0fn t() {}$0
148156"# ,
149157 ) ;
150158 }
@@ -153,7 +161,7 @@ $0fn t() {}
153161 fn works_in_mod ( ) {
154162 // note: /a/b.rs remains untouched
155163 check_assist (
156- promote_mod_file ,
164+ move_to_mod_rs ,
157165 r#"//- /main.rs
158166mod a;
159167//- /a.rs
0 commit comments