Skip to content

Commit 9454a9e

Browse files
committed
Use Module::find_use_path_prefixed in extract_struct_from_enum_variant assist
1 parent e24cc77 commit 9454a9e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

crates/assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ fn insert_import(
135135
variant_hir_name: &Name,
136136
) -> Option<()> {
137137
let db = ctx.db();
138-
let mod_path = module.find_use_path(db, enum_module_def.clone());
139-
if let Some(mut mod_path) = mod_path.filter(|path| path.len() > 1) {
138+
let mod_path = module.find_use_path_prefixed(
139+
db,
140+
enum_module_def.clone(),
141+
ctx.config.insert_use.prefix_kind,
142+
);
143+
if let Some(mut mod_path) = mod_path.filter(|path| !path.is_ident()) {
140144
mod_path.segments.pop();
141145
mod_path.segments.push(variant_hir_name.clone());
142146
let scope = ImportScope::find_insert_use_container(scope_node, ctx)?;
@@ -323,7 +327,7 @@ fn another_fn() {
323327
r#"use my_mod::my_other_mod::MyField;
324328
325329
mod my_mod {
326-
use my_other_mod::MyField;
330+
use self::my_other_mod::MyField;
327331
328332
fn another_fn() {
329333
let m = my_other_mod::MyEnum::MyField(MyField(1, 1));
@@ -402,7 +406,7 @@ enum E {
402406
mod foo;
403407
404408
//- /foo.rs
405-
use crate::E;
409+
use crate::{E, V};
406410
fn f() {
407411
let e = E::V(V(9, 2));
408412
}
@@ -437,7 +441,7 @@ enum E {
437441
mod foo;
438442
439443
//- /foo.rs
440-
use crate::E;
444+
use crate::{E, V};
441445
fn f() {
442446
let e = E::V(V { i: 9, j: 2 });
443447
}

0 commit comments

Comments
 (0)