1
- use crate :: { AssistId , assist_context:: { AssistContext , Assists } } ;
2
- use syntax:: { AstNode , SyntaxKind , SyntaxNode , SyntaxText , ast:: { self , NameOwner } } ;
1
+ use crate :: {
2
+ assist_context:: { AssistContext , Assists } ,
3
+ AssistId ,
4
+ } ;
5
+ use syntax:: {
6
+ ast:: { self , NameOwner } ,
7
+ AstNode , SyntaxKind , SyntaxNode , SyntaxText ,
8
+ } ;
3
9
use test_utils:: mark;
4
10
5
11
// Assist: generate_default_from_new
@@ -51,7 +57,6 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext)
51
57
52
58
let default_fn_syntax = default_fn_node_for_new ( struct_name) ;
53
59
54
-
55
60
acc. add (
56
61
AssistId ( "generate_default_from_new" , crate :: AssistKind :: Generate ) ,
57
62
"Generate a Default impl from a new fn" ,
@@ -72,14 +77,15 @@ fn scope_for_fn_insertion_node(node: &SyntaxNode) -> Option<SyntaxNode> {
72
77
fn default_fn_node_for_new ( struct_name : SyntaxText ) -> String {
73
78
// TODO: Update the implementation to consider the code indentation.
74
79
format ! (
75
- r#"
80
+ r#"
76
81
77
82
impl Default for {} {{
78
83
fn default() -> Self {{
79
84
Self::new()
80
85
}}
81
- }}"#
82
- , struct_name)
86
+ }}"# ,
87
+ struct_name
88
+ )
83
89
}
84
90
85
91
#[ cfg( test) ]
@@ -157,24 +163,26 @@ impl Default for Test {
157
163
#[ test]
158
164
fn new_function_with_parameters ( ) {
159
165
mark:: check!( new_function_with_parameters) ;
160
- check_assist_not_applicable ( generate_default_from_new,
161
- r#"
166
+ check_assist_not_applicable (
167
+ generate_default_from_new,
168
+ r#"
162
169
struct Example { _inner: () }
163
170
164
171
impl Example {
165
172
pub fn $0new(value: ()) -> Self {
166
173
Self { _inner: value }
167
174
}
168
175
}
169
- "#
176
+ "# ,
170
177
) ;
171
178
}
172
179
173
180
#[ test]
174
181
fn other_function_than_new ( ) {
175
182
mark:: check!( other_function_than_new) ;
176
- check_assist_not_applicable ( generate_default_from_new,
177
- r#"
183
+ check_assist_not_applicable (
184
+ generate_default_from_new,
185
+ r#"
178
186
struct Example { _inner: () }
179
187
180
188
impl Exmaple {
@@ -183,39 +191,40 @@ impl Exmaple {
183
191
}
184
192
}
185
193
186
- "#
194
+ "# ,
187
195
) ;
188
196
}
189
197
190
- // #[test]
191
- // fn default_block_is_already_present() {
192
- // check_assist_not_applicable(generate_default_from_new,
193
- // r#"
194
- // struct Example { _inner: () }
195
-
196
- // impl Exmaple {
197
- // pub fn n$0ew() -> Self {
198
- // Self { _inner: () }
199
- // }
200
- // }
201
-
202
- // impl Default for Example {
203
- // fn default() -> Self {
204
- // Self::new()
205
- // }
206
- // }
207
- // "#,
208
- // );
209
- // }
198
+ // #[test]
199
+ // fn default_block_is_already_present() {
200
+ // check_assist_not_applicable(generate_default_from_new,
201
+ // r#"
202
+ // struct Example { _inner: () }
203
+
204
+ // impl Exmaple {
205
+ // pub fn n$0ew() -> Self {
206
+ // Self { _inner: () }
207
+ // }
208
+ // }
209
+
210
+ // impl Default for Example {
211
+ // fn default() -> Self {
212
+ // Self::new()
213
+ // }
214
+ // }
215
+ // "#,
216
+ // );
217
+ // }
210
218
211
219
#[ test]
212
220
fn standalone_new_function ( ) {
213
- check_assist_not_applicable ( generate_default_from_new,
214
- r#"
221
+ check_assist_not_applicable (
222
+ generate_default_from_new,
223
+ r#"
215
224
fn n$0ew() -> u32 {
216
225
0
217
226
}
218
- "#
227
+ "# ,
219
228
) ;
220
229
}
221
230
}
0 commit comments