2 assists::{AssistId, AssistKind},
3 base_db::AnchoredPathBuf,
10 use crate::assist_context::{AssistContext, Assists};
12 pub(crate) fn promote_mod_file(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
13 let source_file = ctx.find_node_at_offset::<ast::SourceFile>()?;
14 let module = ctx.sema.to_module_def(ctx.frange.file_id)?;
15 if module.is_mod_rs(ctx.db()) {
18 let target = TextRange::new(
19 source_file.syntax().text_range().start(),
20 source_file.syntax().text_range().end(),
22 let path = format!("./{}/mod.rs", module.name(ctx.db())?.to_string());
23 let dst = AnchoredPathBuf { anchor: ctx.frange.file_id, path };
25 AssistId("promote_mod_file", AssistKind::Refactor),
26 "Promote Module to directory",
29 builder.move_file(ctx.frange.file_id, dst);
36 use crate::tests::{check_assist, check_assist_not_applicable};
58 fn cursor_can_be_putted_anywhere() {
101 fn cannot_promote_mod_rs() {
102 check_assist_not_applicable(
113 fn cannot_promote_main_and_lib_rs() {
114 check_assist_not_applicable(
120 check_assist_not_applicable(
130 // note: /a/b.rs remains untouched