diff options
author | Lukas Wirth <[email protected]> | 2020-11-12 16:32:45 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-11-12 16:32:45 +0000 |
commit | 9454a9e536d96c7e46378744b8d93cc039fa3b98 (patch) | |
tree | 75bc23073a8a1fea6f53af5fa5d9b10d00e81641 /crates/assists | |
parent | e24cc77cd147b710a0ca161acd2e8d6922e067bd (diff) |
Use Module::find_use_path_prefixed in extract_struct_from_enum_variant assist
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 38ecf5065..ef4dce477 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -135,8 +135,12 @@ fn insert_import( | |||
135 | variant_hir_name: &Name, | 135 | variant_hir_name: &Name, |
136 | ) -> Option<()> { | 136 | ) -> Option<()> { |
137 | let db = ctx.db(); | 137 | let db = ctx.db(); |
138 | let mod_path = module.find_use_path(db, enum_module_def.clone()); | 138 | let mod_path = module.find_use_path_prefixed( |
139 | if let Some(mut mod_path) = mod_path.filter(|path| path.len() > 1) { | 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()) { | ||
140 | mod_path.segments.pop(); | 144 | mod_path.segments.pop(); |
141 | mod_path.segments.push(variant_hir_name.clone()); | 145 | mod_path.segments.push(variant_hir_name.clone()); |
142 | let scope = ImportScope::find_insert_use_container(scope_node, ctx)?; | 146 | let scope = ImportScope::find_insert_use_container(scope_node, ctx)?; |
@@ -323,7 +327,7 @@ fn another_fn() { | |||
323 | r#"use my_mod::my_other_mod::MyField; | 327 | r#"use my_mod::my_other_mod::MyField; |
324 | 328 | ||
325 | mod my_mod { | 329 | mod my_mod { |
326 | use my_other_mod::MyField; | 330 | use self::my_other_mod::MyField; |
327 | 331 | ||
328 | fn another_fn() { | 332 | fn another_fn() { |
329 | let m = my_other_mod::MyEnum::MyField(MyField(1, 1)); | 333 | let m = my_other_mod::MyEnum::MyField(MyField(1, 1)); |
@@ -402,7 +406,7 @@ enum E { | |||
402 | mod foo; | 406 | mod foo; |
403 | 407 | ||
404 | //- /foo.rs | 408 | //- /foo.rs |
405 | use crate::E; | 409 | use crate::{E, V}; |
406 | fn f() { | 410 | fn f() { |
407 | let e = E::V(V(9, 2)); | 411 | let e = E::V(V(9, 2)); |
408 | } | 412 | } |
@@ -437,7 +441,7 @@ enum E { | |||
437 | mod foo; | 441 | mod foo; |
438 | 442 | ||
439 | //- /foo.rs | 443 | //- /foo.rs |
440 | use crate::E; | 444 | use crate::{E, V}; |
441 | fn f() { | 445 | fn f() { |
442 | let e = E::V(V { i: 9, j: 2 }); | 446 | let e = E::V(V { i: 9, j: 2 }); |
443 | } | 447 | } |