Skip to content

Commit fafcc77

Browse files
committed
fix: extract mod to file should respect path attribute
1 parent 48bcef3 commit fafcc77

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/move_module_to_file.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::iter;
22

33
use ast::edit::IndentLevel;
4+
use hir::HasAttrs;
45
use ide_db::base_db::AnchoredPathBuf;
56
use itertools::Itertools;
67
use stdx::format_to;
@@ -50,9 +51,17 @@ pub(crate) fn move_module_to_file(acc: &mut Assists, ctx: &AssistContext<'_>) ->
5051
|builder| {
5152
let path = {
5253
let mut buf = String::from("./");
53-
match parent_module.name(ctx.db()) {
54-
Some(name) if !parent_module.is_mod_rs(ctx.db()) => {
55-
format_to!(buf, "{}/", name.display(ctx.db()))
54+
let db = ctx.db();
55+
match parent_module.name(db) {
56+
Some(name)
57+
if !parent_module.is_mod_rs(db)
58+
&& parent_module
59+
.attrs(db)
60+
.by_key("path")
61+
.string_value_unescape()
62+
.is_none() =>
63+
{
64+
format_to!(buf, "{}/", name.display(db))
5665
}
5766
_ => (),
5867
}

0 commit comments

Comments
 (0)