aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/assists/src/handlers/move_module_to_file.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/crates/assists/src/handlers/move_module_to_file.rs b/crates/assists/src/handlers/move_module_to_file.rs
index 1f2d8f20f..91c395c1b 100644
--- a/crates/assists/src/handlers/move_module_to_file.rs
+++ b/crates/assists/src/handlers/move_module_to_file.rs
@@ -1,5 +1,6 @@
1use ast::{edit::IndentLevel, VisibilityOwner}; 1use ast::{edit::IndentLevel, VisibilityOwner};
2use ide_db::base_db::AnchoredPathBuf; 2use ide_db::base_db::AnchoredPathBuf;
3use stdx::format_to;
3use syntax::{ 4use syntax::{
4 ast::{self, edit::AstNodeEdit, NameOwner}, 5 ast::{self, edit::AstNodeEdit, NameOwner},
5 AstNode, TextRange, 6 AstNode, TextRange,
@@ -36,8 +37,6 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Opt
36 37
37 let module_def = ctx.sema.to_def(&module_ast)?; 38 let module_def = ctx.sema.to_def(&module_ast)?;
38 let parent_module = module_def.parent(ctx.db())?; 39 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() };
41 40
42 acc.add( 41 acc.add(
43 AssistId("move_module_to_file", AssistKind::RefactorExtract), 42 AssistId("move_module_to_file", AssistKind::RefactorExtract),
@@ -61,10 +60,13 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext) -> Opt
61 items 60 items
62 }; 61 };
63 62
64 builder.replace( 63 let mut buf = String::new();
65 module_ast.syntax().text_range(), 64 if let Some(v) = module_ast.visibility() {
66 format!("{}mod {};", vis_str, module_name), 65 format_to!(buf, "{} ", v);
67 ); 66 }
67 format_to!(buf, "mod {};", module_name);
68
69 builder.replace(module_ast.syntax().text_range(), buf);
68 70
69 let dst = AnchoredPathBuf { anchor: ctx.frange.file_id, path }; 71 let dst = AnchoredPathBuf { anchor: ctx.frange.file_id, path };
70 builder.create_file(dst, contents); 72 builder.create_file(dst, contents);