aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs13
-rw-r--r--crates/ra_assists/src/utils/insert_use.rs11
2 files changed, 19 insertions, 5 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
10use crate::{ 10use 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};
15use ast::{ArgListOwner, VisibilityOwner}; 15use ast::{ArgListOwner, VisibilityOwner};
16use hir::{AsName, EnumVariant, Module, ModuleDef}; 16use hir::{EnumVariant, Module, ModuleDef};
17use ra_db::FileId; 17use ra_db::FileId;
18use ra_fmt::leading_indent; 18use ra_fmt::leading_indent;
19use rustc_hash::FxHashSet; 19use 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
29pub(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());