diff options
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r-- | crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs | 16 |
1 files changed, 6 insertions, 10 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 6e9f2d0fc..497f887cd 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 | |||
@@ -1,12 +1,11 @@ | |||
1 | use hir::{EnumVariant, Module, ModuleDef, Name}; | 1 | use hir::{EnumVariant, Module, ModuleDef, Name}; |
2 | use ra_db::FileId; | 2 | use ra_db::FileId; |
3 | use ra_fmt::leading_indent; | ||
4 | use ra_ide_db::{defs::Definition, search::Reference, RootDatabase}; | 3 | use ra_ide_db::{defs::Definition, search::Reference, RootDatabase}; |
5 | use rustc_hash::FxHashSet; | 4 | use rustc_hash::FxHashSet; |
6 | use syntax::{ | 5 | use syntax::{ |
7 | algo::find_node_at_offset, | 6 | algo::find_node_at_offset, |
8 | ast::{self, ArgListOwner, AstNode, NameOwner, VisibilityOwner}, | 7 | ast::{self, edit::IndentLevel, ArgListOwner, AstNode, NameOwner, VisibilityOwner}, |
9 | SourceFile, SyntaxNode, TextRange, TextSize, | 8 | SourceFile, TextRange, TextSize, |
10 | }; | 9 | }; |
11 | 10 | ||
12 | use crate::{ | 11 | use crate::{ |
@@ -72,7 +71,7 @@ pub(crate) fn extract_struct_from_enum_variant( | |||
72 | } | 71 | } |
73 | extract_struct_def( | 72 | extract_struct_def( |
74 | builder, | 73 | builder, |
75 | enum_ast.syntax(), | 74 | &enum_ast, |
76 | &variant_name, | 75 | &variant_name, |
77 | &field_list.to_string(), | 76 | &field_list.to_string(), |
78 | start_offset, | 77 | start_offset, |
@@ -112,9 +111,10 @@ fn insert_import( | |||
112 | Some(()) | 111 | Some(()) |
113 | } | 112 | } |
114 | 113 | ||
114 | // FIXME: this should use strongly-typed `make`, rather than string manipulation. | ||
115 | fn extract_struct_def( | 115 | fn extract_struct_def( |
116 | builder: &mut AssistBuilder, | 116 | builder: &mut AssistBuilder, |
117 | enum_ast: &SyntaxNode, | 117 | enum_: &ast::Enum, |
118 | variant_name: &str, | 118 | variant_name: &str, |
119 | variant_list: &str, | 119 | variant_list: &str, |
120 | start_offset: TextSize, | 120 | start_offset: TextSize, |
@@ -126,11 +126,7 @@ fn extract_struct_def( | |||
126 | } else { | 126 | } else { |
127 | "".to_string() | 127 | "".to_string() |
128 | }; | 128 | }; |
129 | let indent = if let Some(indent) = leading_indent(enum_ast) { | 129 | let indent = IndentLevel::from_node(enum_.syntax()); |
130 | indent.to_string() | ||
131 | } else { | ||
132 | "".to_string() | ||
133 | }; | ||
134 | let struct_def = format!( | 130 | let struct_def = format!( |
135 | r#"{}struct {}{}; | 131 | r#"{}struct {}{}; |
136 | 132 | ||