Use Module::find_use_path_prefixed in extract_struct_from_enum_variant assist
This commit is contained in:
parent
e24cc77cd1
commit
9454a9e536
@ -135,8 +135,12 @@ fn insert_import(
|
|||||||
variant_hir_name: &Name,
|
variant_hir_name: &Name,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let db = ctx.db();
|
let db = ctx.db();
|
||||||
let mod_path = module.find_use_path(db, enum_module_def.clone());
|
let mod_path = module.find_use_path_prefixed(
|
||||||
if let Some(mut mod_path) = mod_path.filter(|path| path.len() > 1) {
|
db,
|
||||||
|
enum_module_def.clone(),
|
||||||
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
);
|
||||||
|
if let Some(mut mod_path) = mod_path.filter(|path| !path.is_ident()) {
|
||||||
mod_path.segments.pop();
|
mod_path.segments.pop();
|
||||||
mod_path.segments.push(variant_hir_name.clone());
|
mod_path.segments.push(variant_hir_name.clone());
|
||||||
let scope = ImportScope::find_insert_use_container(scope_node, ctx)?;
|
let scope = ImportScope::find_insert_use_container(scope_node, ctx)?;
|
||||||
@ -323,7 +327,7 @@ fn another_fn() {
|
|||||||
r#"use my_mod::my_other_mod::MyField;
|
r#"use my_mod::my_other_mod::MyField;
|
||||||
|
|
||||||
mod my_mod {
|
mod my_mod {
|
||||||
use my_other_mod::MyField;
|
use self::my_other_mod::MyField;
|
||||||
|
|
||||||
fn another_fn() {
|
fn another_fn() {
|
||||||
let m = my_other_mod::MyEnum::MyField(MyField(1, 1));
|
let m = my_other_mod::MyEnum::MyField(MyField(1, 1));
|
||||||
@ -402,7 +406,7 @@ enum E {
|
|||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
use crate::E;
|
use crate::{E, V};
|
||||||
fn f() {
|
fn f() {
|
||||||
let e = E::V(V(9, 2));
|
let e = E::V(V(9, 2));
|
||||||
}
|
}
|
||||||
@ -437,7 +441,7 @@ enum E {
|
|||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
//- /foo.rs
|
//- /foo.rs
|
||||||
use crate::E;
|
use crate::{E, V};
|
||||||
fn f() {
|
fn f() {
|
||||||
let e = E::V(V { i: 9, j: 2 });
|
let e = E::V(V { i: 9, j: 2 });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user