@@ -11,7 +11,7 @@ use test_utils::mark;
11
11
12
12
use crate :: { AssistContext , AssistId , Assists } ;
13
13
14
- // Assist: introduce_variable
14
+ // Assist: extract_variable
15
15
//
16
16
// Extracts subexpression into a variable.
17
17
//
@@ -27,13 +27,13 @@ use crate::{AssistContext, AssistId, Assists};
27
27
// var_name * 4;
28
28
// }
29
29
// ```
30
- pub ( crate ) fn introduce_variable ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
30
+ pub ( crate ) fn extract_variable ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
31
31
if ctx. frange . range . is_empty ( ) {
32
32
return None ;
33
33
}
34
34
let node = ctx. covering_element ( ) ;
35
35
if node. kind ( ) == COMMENT {
36
- mark:: hit!( introduce_var_in_comment_is_not_applicable ) ;
36
+ mark:: hit!( extract_var_in_comment_is_not_applicable ) ;
37
37
return None ;
38
38
}
39
39
let expr = node. ancestors ( ) . find_map ( valid_target_expr) ?;
@@ -43,7 +43,7 @@ pub(crate) fn introduce_variable(acc: &mut Assists, ctx: &AssistContext) -> Opti
43
43
return None ;
44
44
}
45
45
let target = expr. syntax ( ) . text_range ( ) ;
46
- acc. add ( AssistId ( "introduce_variable " ) , "Extract into variable" , target, move |edit| {
46
+ acc. add ( AssistId ( "extract_variable " ) , "Extract into variable" , target, move |edit| {
47
47
let field_shorthand = match expr. syntax ( ) . parent ( ) . and_then ( ast:: RecordField :: cast) {
48
48
Some ( field) => field. name_ref ( ) ,
49
49
None => None ,
@@ -74,7 +74,7 @@ pub(crate) fn introduce_variable(acc: &mut Assists, ctx: &AssistContext) -> Opti
74
74
false
75
75
} ;
76
76
if is_full_stmt {
77
- mark:: hit!( test_introduce_var_expr_stmt ) ;
77
+ mark:: hit!( test_extract_var_expr_stmt ) ;
78
78
if full_stmt. unwrap ( ) . semicolon_token ( ) . is_none ( ) {
79
79
buf. push_str ( ";" ) ;
80
80
}
@@ -133,7 +133,7 @@ fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> {
133
133
}
134
134
}
135
135
136
- /// Returns the syntax node which will follow the freshly introduced var
136
+ /// Returns the syntax node which will follow the freshly extractd var
137
137
/// and a boolean indicating whether we have to wrap it within a { } block
138
138
/// to produce correct code.
139
139
/// It can be a statement, the last in a block expression or a wanna be block
@@ -142,7 +142,7 @@ fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> {
142
142
expr. syntax ( ) . ancestors ( ) . find_map ( |node| {
143
143
if let Some ( expr) = node. parent ( ) . and_then ( ast:: BlockExpr :: cast) . and_then ( |it| it. expr ( ) ) {
144
144
if expr. syntax ( ) == & node {
145
- mark:: hit!( test_introduce_var_last_expr ) ;
145
+ mark:: hit!( test_extract_var_last_expr ) ;
146
146
return Some ( ( node, false ) ) ;
147
147
}
148
148
}
@@ -170,9 +170,9 @@ mod tests {
170
170
use super :: * ;
171
171
172
172
#[ test]
173
- fn test_introduce_var_simple ( ) {
173
+ fn test_extract_var_simple ( ) {
174
174
check_assist (
175
- introduce_variable ,
175
+ extract_variable ,
176
176
r#"
177
177
fn foo() {
178
178
foo(<|>1 + 1<|>);
@@ -186,16 +186,16 @@ fn foo() {
186
186
}
187
187
188
188
#[ test]
189
- fn introduce_var_in_comment_is_not_applicable ( ) {
190
- mark:: check!( introduce_var_in_comment_is_not_applicable ) ;
191
- check_assist_not_applicable ( introduce_variable , "fn main() { 1 + /* <|>comment<|> */ 1; }" ) ;
189
+ fn extract_var_in_comment_is_not_applicable ( ) {
190
+ mark:: check!( extract_var_in_comment_is_not_applicable ) ;
191
+ check_assist_not_applicable ( extract_variable , "fn main() { 1 + /* <|>comment<|> */ 1; }" ) ;
192
192
}
193
193
194
194
#[ test]
195
- fn test_introduce_var_expr_stmt ( ) {
196
- mark:: check!( test_introduce_var_expr_stmt ) ;
195
+ fn test_extract_var_expr_stmt ( ) {
196
+ mark:: check!( test_extract_var_expr_stmt ) ;
197
197
check_assist (
198
- introduce_variable ,
198
+ extract_variable ,
199
199
r#"
200
200
fn foo() {
201
201
<|>1 + 1<|>;
@@ -206,7 +206,7 @@ fn foo() {
206
206
}"# ,
207
207
) ;
208
208
check_assist (
209
- introduce_variable ,
209
+ extract_variable ,
210
210
"
211
211
fn foo() {
212
212
<|>{ let x = 0; x }<|>
@@ -221,9 +221,9 @@ fn foo() {
221
221
}
222
222
223
223
#[ test]
224
- fn test_introduce_var_part_of_expr_stmt ( ) {
224
+ fn test_extract_var_part_of_expr_stmt ( ) {
225
225
check_assist (
226
- introduce_variable ,
226
+ extract_variable ,
227
227
"
228
228
fn foo() {
229
229
<|>1<|> + 1;
@@ -237,10 +237,10 @@ fn foo() {
237
237
}
238
238
239
239
#[ test]
240
- fn test_introduce_var_last_expr ( ) {
241
- mark:: check!( test_introduce_var_last_expr ) ;
240
+ fn test_extract_var_last_expr ( ) {
241
+ mark:: check!( test_extract_var_last_expr ) ;
242
242
check_assist (
243
- introduce_variable ,
243
+ extract_variable ,
244
244
r#"
245
245
fn foo() {
246
246
bar(<|>1 + 1<|>)
@@ -254,7 +254,7 @@ fn foo() {
254
254
"# ,
255
255
) ;
256
256
check_assist (
257
- introduce_variable ,
257
+ extract_variable ,
258
258
r#"
259
259
fn foo() {
260
260
<|>bar(1 + 1)<|>
@@ -270,9 +270,9 @@ fn foo() {
270
270
}
271
271
272
272
#[ test]
273
- fn test_introduce_var_in_match_arm_no_block ( ) {
273
+ fn test_extract_var_in_match_arm_no_block ( ) {
274
274
check_assist (
275
- introduce_variable ,
275
+ extract_variable ,
276
276
"
277
277
fn main() {
278
278
let x = true;
@@ -295,9 +295,9 @@ fn main() {
295
295
}
296
296
297
297
#[ test]
298
- fn test_introduce_var_in_match_arm_with_block ( ) {
298
+ fn test_extract_var_in_match_arm_with_block ( ) {
299
299
check_assist (
300
- introduce_variable ,
300
+ extract_variable ,
301
301
"
302
302
fn main() {
303
303
let x = true;
@@ -327,9 +327,9 @@ fn main() {
327
327
}
328
328
329
329
#[ test]
330
- fn test_introduce_var_in_closure_no_block ( ) {
330
+ fn test_extract_var_in_closure_no_block ( ) {
331
331
check_assist (
332
- introduce_variable ,
332
+ extract_variable ,
333
333
"
334
334
fn main() {
335
335
let lambda = |x: u32| <|>x * 2<|>;
@@ -344,9 +344,9 @@ fn main() {
344
344
}
345
345
346
346
#[ test]
347
- fn test_introduce_var_in_closure_with_block ( ) {
347
+ fn test_extract_var_in_closure_with_block ( ) {
348
348
check_assist (
349
- introduce_variable ,
349
+ extract_variable ,
350
350
"
351
351
fn main() {
352
352
let lambda = |x: u32| { <|>x * 2<|> };
@@ -361,9 +361,9 @@ fn main() {
361
361
}
362
362
363
363
#[ test]
364
- fn test_introduce_var_path_simple ( ) {
364
+ fn test_extract_var_path_simple ( ) {
365
365
check_assist (
366
- introduce_variable ,
366
+ extract_variable ,
367
367
"
368
368
fn main() {
369
369
let o = <|>Some(true)<|>;
@@ -379,9 +379,9 @@ fn main() {
379
379
}
380
380
381
381
#[ test]
382
- fn test_introduce_var_path_method ( ) {
382
+ fn test_extract_var_path_method ( ) {
383
383
check_assist (
384
- introduce_variable ,
384
+ extract_variable ,
385
385
"
386
386
fn main() {
387
387
let v = <|>bar.foo()<|>;
@@ -397,9 +397,9 @@ fn main() {
397
397
}
398
398
399
399
#[ test]
400
- fn test_introduce_var_return ( ) {
400
+ fn test_extract_var_return ( ) {
401
401
check_assist (
402
- introduce_variable ,
402
+ extract_variable ,
403
403
"
404
404
fn foo() -> u32 {
405
405
<|>return 2 + 2<|>;
@@ -415,9 +415,9 @@ fn foo() -> u32 {
415
415
}
416
416
417
417
#[ test]
418
- fn test_introduce_var_does_not_add_extra_whitespace ( ) {
418
+ fn test_extract_var_does_not_add_extra_whitespace ( ) {
419
419
check_assist (
420
- introduce_variable ,
420
+ extract_variable ,
421
421
"
422
422
fn foo() -> u32 {
423
423
@@ -436,7 +436,7 @@ fn foo() -> u32 {
436
436
) ;
437
437
438
438
check_assist (
439
- introduce_variable ,
439
+ extract_variable ,
440
440
"
441
441
fn foo() -> u32 {
442
442
@@ -453,7 +453,7 @@ fn foo() -> u32 {
453
453
) ;
454
454
455
455
check_assist (
456
- introduce_variable ,
456
+ extract_variable ,
457
457
"
458
458
fn foo() -> u32 {
459
459
let foo = 1;
@@ -479,9 +479,9 @@ fn foo() -> u32 {
479
479
}
480
480
481
481
#[ test]
482
- fn test_introduce_var_break ( ) {
482
+ fn test_extract_var_break ( ) {
483
483
check_assist (
484
- introduce_variable ,
484
+ extract_variable ,
485
485
"
486
486
fn main() {
487
487
let result = loop {
@@ -501,9 +501,9 @@ fn main() {
501
501
}
502
502
503
503
#[ test]
504
- fn test_introduce_var_for_cast ( ) {
504
+ fn test_extract_var_for_cast ( ) {
505
505
check_assist (
506
- introduce_variable ,
506
+ extract_variable ,
507
507
"
508
508
fn main() {
509
509
let v = <|>0f32 as u32<|>;
@@ -519,9 +519,9 @@ fn main() {
519
519
}
520
520
521
521
#[ test]
522
- fn introduce_var_field_shorthand ( ) {
522
+ fn extract_var_field_shorthand ( ) {
523
523
check_assist (
524
- introduce_variable ,
524
+ extract_variable ,
525
525
r#"
526
526
struct S {
527
527
foo: i32
@@ -545,22 +545,22 @@ fn main() {
545
545
}
546
546
547
547
#[ test]
548
- fn test_introduce_var_for_return_not_applicable ( ) {
549
- check_assist_not_applicable ( introduce_variable , "fn foo() { <|>return<|>; } " ) ;
548
+ fn test_extract_var_for_return_not_applicable ( ) {
549
+ check_assist_not_applicable ( extract_variable , "fn foo() { <|>return<|>; } " ) ;
550
550
}
551
551
552
552
#[ test]
553
- fn test_introduce_var_for_break_not_applicable ( ) {
554
- check_assist_not_applicable ( introduce_variable , "fn main() { loop { <|>break<|>; }; }" ) ;
553
+ fn test_extract_var_for_break_not_applicable ( ) {
554
+ check_assist_not_applicable ( extract_variable , "fn main() { loop { <|>break<|>; }; }" ) ;
555
555
}
556
556
557
557
// FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic
558
558
#[ test]
559
- fn introduce_var_target ( ) {
560
- check_assist_target ( introduce_variable , "fn foo() -> u32 { <|>return 2 + 2<|>; }" , "2 + 2" ) ;
559
+ fn extract_var_target ( ) {
560
+ check_assist_target ( extract_variable , "fn foo() -> u32 { <|>return 2 + 2<|>; }" , "2 + 2" ) ;
561
561
562
562
check_assist_target (
563
- introduce_variable ,
563
+ extract_variable ,
564
564
"
565
565
fn main() {
566
566
let x = true;
0 commit comments