diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | 13 | ||||
-rw-r--r-- | crates/ra_assists/src/utils/insert_use.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 5 |
3 files changed, 21 insertions, 8 deletions
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs index 2b1951aff..72e5dd735 100644 --- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -9,11 +9,11 @@ use ra_syntax::{ | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | assist_context::{AssistBuilder, AssistDirector}, | 11 | assist_context::{AssistBuilder, AssistDirector}, |
12 | utils::insert_use_statement, | 12 | utils::insert_use::insert_use_statement_with_string_path, |
13 | AssistContext, AssistId, Assists, | 13 | AssistContext, AssistId, Assists, |
14 | }; | 14 | }; |
15 | use ast::{ArgListOwner, VisibilityOwner}; | 15 | use ast::{ArgListOwner, VisibilityOwner}; |
16 | use hir::{AsName, EnumVariant, Module, ModuleDef}; | 16 | use hir::{EnumVariant, Module, ModuleDef}; |
17 | use ra_db::FileId; | 17 | use ra_db::FileId; |
18 | use ra_fmt::leading_indent; | 18 | use ra_fmt::leading_indent; |
19 | use rustc_hash::FxHashSet; | 19 | use rustc_hash::FxHashSet; |
@@ -109,8 +109,13 @@ fn insert_import( | |||
109 | let mod_path = module.find_use_path(db, module_def.clone()); | 109 | let mod_path = module.find_use_path(db, module_def.clone()); |
110 | if let Some(mut mod_path) = mod_path { | 110 | if let Some(mut mod_path) = mod_path { |
111 | mod_path.segments.pop(); | 111 | mod_path.segments.pop(); |
112 | mod_path.segments.push(path_segment.as_name()); | 112 | let use_path = format!("{}::{}", mod_path.to_string(), path_segment.to_string()); |
113 | insert_use_statement(path.syntax(), &mod_path, ctx, builder.text_edit_builder()); | 113 | insert_use_statement_with_string_path( |
114 | path.syntax(), | ||
115 | &use_path, | ||
116 | ctx, | ||
117 | builder.text_edit_builder(), | ||
118 | ); | ||
114 | } | 119 | } |
115 | Some(()) | 120 | Some(()) |
116 | } | 121 | } |
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs index 0ee43482f..114f5949a 100644 --- a/crates/ra_assists/src/utils/insert_use.rs +++ b/crates/ra_assists/src/utils/insert_use.rs | |||
@@ -23,7 +23,16 @@ pub(crate) fn insert_use_statement( | |||
23 | ctx: &AssistContext, | 23 | ctx: &AssistContext, |
24 | builder: &mut TextEditBuilder, | 24 | builder: &mut TextEditBuilder, |
25 | ) { | 25 | ) { |
26 | let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::<Vec<_>>(); | 26 | insert_use_statement_with_string_path(position, &path_to_import.to_string(), ctx, builder); |
27 | } | ||
28 | |||
29 | pub(crate) fn insert_use_statement_with_string_path( | ||
30 | position: &SyntaxNode, | ||
31 | path_to_import: &str, | ||
32 | ctx: &AssistContext, | ||
33 | builder: &mut TextEditBuilder, | ||
34 | ) { | ||
35 | let target = path_to_import.split("::").map(SmolStr::new).collect::<Vec<_>>(); | ||
27 | let container = ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| { | 36 | let container = ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| { |
28 | if let Some(module) = ast::Module::cast(n.clone()) { | 37 | if let Some(module) = ast::Module::cast(n.clone()) { |
29 | return module.item_list().map(|it| it.syntax().clone()); | 38 | return module.item_list().map(|it| it.syntax().clone()); |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index f4a6b0503..3364a822f 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -71,8 +71,7 @@ pub use hir_def::{ | |||
71 | type_ref::Mutability, | 71 | type_ref::Mutability, |
72 | }; | 72 | }; |
73 | pub use hir_expand::{ | 73 | pub use hir_expand::{ |
74 | hygiene::Hygiene, | 74 | hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, |
75 | name::{AsName, Name}, | 75 | MacroFile, Origin, |
76 | HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin, | ||
77 | }; | 76 | }; |
78 | pub use hir_ty::{display::HirDisplay, CallableDef}; | 77 | pub use hir_ty::{display::HirDisplay, CallableDef}; |