1
- use ast:: edit:: IndentLevel ;
1
+ use ast:: { edit:: IndentLevel , VisibilityOwner } ;
2
2
use ide_db:: base_db:: AnchoredPathBuf ;
3
3
use syntax:: {
4
4
ast:: { self , edit:: AstNodeEdit , NameOwner } ,
@@ -36,6 +36,8 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Opt
36
36
37
37
let module_def = ctx. sema . to_def ( & module_ast) ?;
38
38
let parent_module = module_def. parent ( ctx. db ( ) ) ?;
39
+ let vis_str =
40
+ if let Some ( v) = module_ast. visibility ( ) { v. to_string ( ) + " " } else { "" . to_string ( ) } ;
39
41
40
42
acc. add (
41
43
AssistId ( "move_module_to_file" , AssistKind :: RefactorExtract ) ,
@@ -59,7 +61,10 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Opt
59
61
items
60
62
} ;
61
63
62
- builder. replace ( module_ast. syntax ( ) . text_range ( ) , format ! ( "mod {};" , module_name) ) ;
64
+ builder. replace (
65
+ module_ast. syntax ( ) . text_range ( ) ,
66
+ format ! ( "{}mod {};" , vis_str, module_name) ,
67
+ ) ;
63
68
64
69
let dst = AnchoredPathBuf { anchor : ctx. frange . file_id , path } ;
65
70
builder. create_file ( dst, contents) ;
@@ -137,6 +142,42 @@ fn f() {}
137
142
) ;
138
143
}
139
144
145
+ #[ test]
146
+ fn extract_public ( ) {
147
+ check_assist (
148
+ move_module_to_file,
149
+ r#"
150
+ pub mod $0tests {
151
+ #[test] fn t() {}
152
+ }
153
+ "# ,
154
+ r#"
155
+ //- /main.rs
156
+ pub mod tests;
157
+ //- /tests.rs
158
+ #[test] fn t() {}
159
+ "# ,
160
+ ) ;
161
+ }
162
+
163
+ #[ test]
164
+ fn extract_public_crate ( ) {
165
+ check_assist (
166
+ move_module_to_file,
167
+ r#"
168
+ pub(crate) mod $0tests {
169
+ #[test] fn t() {}
170
+ }
171
+ "# ,
172
+ r#"
173
+ //- /main.rs
174
+ pub(crate) mod tests;
175
+ //- /tests.rs
176
+ #[test] fn t() {}
177
+ "# ,
178
+ ) ;
179
+ }
180
+
140
181
#[ test]
141
182
fn available_before_curly ( ) {
142
183
mark:: check!( available_before_curly) ;
0 commit comments