aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs10
1 files changed, 3 insertions, 7 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 dd2fd57a7..a36587633 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
@@ -6,7 +6,6 @@ use ra_syntax::{
6 ast::{self, AstNode, NameOwner}, 6 ast::{self, AstNode, NameOwner},
7 SourceFile, SyntaxNode, TextRange, TextSize, 7 SourceFile, SyntaxNode, TextRange, TextSize,
8}; 8};
9use stdx::format_to;
10 9
11use crate::{ 10use crate::{
12 assist_context::{AssistBuilder, AssistDirector}, 11 assist_context::{AssistBuilder, AssistDirector},
@@ -58,7 +57,7 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
58 let definition = Definition::ModuleDef(ModuleDef::EnumVariant(variant_hir)); 57 let definition = Definition::ModuleDef(ModuleDef::EnumVariant(variant_hir));
59 let res = definition.find_usages(&ctx.db, None); 58 let res = definition.find_usages(&ctx.db, None);
60 let start_offset = variant.parent_enum().syntax().text_range().start(); 59 let start_offset = variant.parent_enum().syntax().text_range().start();
61 let mut visited_modules_set: FxHashSet<Module> = FxHashSet::default(); 60 let mut visited_modules_set = FxHashSet::default();
62 visited_modules_set.insert(current_module); 61 visited_modules_set.insert(current_module);
63 for reference in res { 62 for reference in res {
64 let source_file = ctx.sema.parse(reference.file_range.file_id); 63 let source_file = ctx.sema.parse(reference.file_range.file_id);
@@ -132,10 +131,7 @@ fn extract_struct_def(
132 } else { 131 } else {
133 "".to_string() 132 "".to_string()
134 }; 133 };
135 let mut buf = String::new(); 134 let struct_def = format!(
136
137 format_to!(
138 buf,
139 r#"{}struct {}{}; 135 r#"{}struct {}{};
140 136
141{}"#, 137{}"#,
@@ -145,7 +141,7 @@ fn extract_struct_def(
145 indent 141 indent
146 ); 142 );
147 edit.perform(file_id, |builder| { 143 edit.perform(file_id, |builder| {
148 builder.insert(start_offset, buf); 144 builder.insert(start_offset, struct_def);
149 }); 145 });
150 Some(()) 146 Some(())
151} 147}