@@ -11,7 +11,7 @@ use test_utils::mark;
1111
1212use crate :: { AssistContext , AssistId , Assists } ;
1313
14- // Assist: introduce_variable
14+ // Assist: extract_variable
1515//
1616// Extracts subexpression into a variable.
1717//
@@ -27,13 +27,13 @@ use crate::{AssistContext, AssistId, Assists};
2727// var_name * 4;
2828// }
2929// ```
30- pub ( crate ) fn introduce_variable ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
30+ pub ( crate ) fn extract_variable ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > {
3131 if ctx. frange . range . is_empty ( ) {
3232 return None ;
3333 }
3434 let node = ctx. covering_element ( ) ;
3535 if node. kind ( ) == COMMENT {
36- mark:: hit!( introduce_var_in_comment_is_not_applicable ) ;
36+ mark:: hit!( extract_var_in_comment_is_not_applicable ) ;
3737 return None ;
3838 }
3939 let expr = node. ancestors ( ) . find_map ( valid_target_expr) ?;
@@ -43,7 +43,7 @@ pub(crate) fn introduce_variable(acc: &mut Assists, ctx: &AssistContext) -> Opti
4343 return None ;
4444 }
4545 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| {
4747 let field_shorthand = match expr. syntax ( ) . parent ( ) . and_then ( ast:: RecordField :: cast) {
4848 Some ( field) => field. name_ref ( ) ,
4949 None => None ,
@@ -74,7 +74,7 @@ pub(crate) fn introduce_variable(acc: &mut Assists, ctx: &AssistContext) -> Opti
7474 false
7575 } ;
7676 if is_full_stmt {
77- mark:: hit!( test_introduce_var_expr_stmt ) ;
77+ mark:: hit!( test_extract_var_expr_stmt ) ;
7878 if full_stmt. unwrap ( ) . semicolon_token ( ) . is_none ( ) {
7979 buf. push_str ( ";" ) ;
8080 }
@@ -133,7 +133,7 @@ fn valid_target_expr(node: SyntaxNode) -> Option<ast::Expr> {
133133 }
134134}
135135
136- /// Returns the syntax node which will follow the freshly introduced var
136+ /// Returns the syntax node which will follow the freshly extractd var
137137/// and a boolean indicating whether we have to wrap it within a { } block
138138/// to produce correct code.
139139/// 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)> {
142142 expr. syntax ( ) . ancestors ( ) . find_map ( |node| {
143143 if let Some ( expr) = node. parent ( ) . and_then ( ast:: BlockExpr :: cast) . and_then ( |it| it. expr ( ) ) {
144144 if expr. syntax ( ) == & node {
145- mark:: hit!( test_introduce_var_last_expr ) ;
145+ mark:: hit!( test_extract_var_last_expr ) ;
146146 return Some ( ( node, false ) ) ;
147147 }
148148 }
@@ -170,9 +170,9 @@ mod tests {
170170 use super :: * ;
171171
172172 #[ test]
173- fn test_introduce_var_simple ( ) {
173+ fn test_extract_var_simple ( ) {
174174 check_assist (
175- introduce_variable ,
175+ extract_variable ,
176176 r#"
177177fn foo() {
178178 foo(<|>1 + 1<|>);
@@ -186,16 +186,16 @@ fn foo() {
186186 }
187187
188188 #[ 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; }" ) ;
192192 }
193193
194194 #[ 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 ) ;
197197 check_assist (
198- introduce_variable ,
198+ extract_variable ,
199199 r#"
200200fn foo() {
201201 <|>1 + 1<|>;
@@ -206,7 +206,7 @@ fn foo() {
206206}"# ,
207207 ) ;
208208 check_assist (
209- introduce_variable ,
209+ extract_variable ,
210210 "
211211fn foo() {
212212 <|>{ let x = 0; x }<|>
@@ -221,9 +221,9 @@ fn foo() {
221221 }
222222
223223 #[ test]
224- fn test_introduce_var_part_of_expr_stmt ( ) {
224+ fn test_extract_var_part_of_expr_stmt ( ) {
225225 check_assist (
226- introduce_variable ,
226+ extract_variable ,
227227 "
228228fn foo() {
229229 <|>1<|> + 1;
@@ -237,10 +237,10 @@ fn foo() {
237237 }
238238
239239 #[ 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 ) ;
242242 check_assist (
243- introduce_variable ,
243+ extract_variable ,
244244 r#"
245245fn foo() {
246246 bar(<|>1 + 1<|>)
@@ -254,7 +254,7 @@ fn foo() {
254254"# ,
255255 ) ;
256256 check_assist (
257- introduce_variable ,
257+ extract_variable ,
258258 r#"
259259fn foo() {
260260 <|>bar(1 + 1)<|>
@@ -270,9 +270,9 @@ fn foo() {
270270 }
271271
272272 #[ test]
273- fn test_introduce_var_in_match_arm_no_block ( ) {
273+ fn test_extract_var_in_match_arm_no_block ( ) {
274274 check_assist (
275- introduce_variable ,
275+ extract_variable ,
276276 "
277277fn main() {
278278 let x = true;
@@ -295,9 +295,9 @@ fn main() {
295295 }
296296
297297 #[ test]
298- fn test_introduce_var_in_match_arm_with_block ( ) {
298+ fn test_extract_var_in_match_arm_with_block ( ) {
299299 check_assist (
300- introduce_variable ,
300+ extract_variable ,
301301 "
302302fn main() {
303303 let x = true;
@@ -327,9 +327,9 @@ fn main() {
327327 }
328328
329329 #[ test]
330- fn test_introduce_var_in_closure_no_block ( ) {
330+ fn test_extract_var_in_closure_no_block ( ) {
331331 check_assist (
332- introduce_variable ,
332+ extract_variable ,
333333 "
334334fn main() {
335335 let lambda = |x: u32| <|>x * 2<|>;
@@ -344,9 +344,9 @@ fn main() {
344344 }
345345
346346 #[ test]
347- fn test_introduce_var_in_closure_with_block ( ) {
347+ fn test_extract_var_in_closure_with_block ( ) {
348348 check_assist (
349- introduce_variable ,
349+ extract_variable ,
350350 "
351351fn main() {
352352 let lambda = |x: u32| { <|>x * 2<|> };
@@ -361,9 +361,9 @@ fn main() {
361361 }
362362
363363 #[ test]
364- fn test_introduce_var_path_simple ( ) {
364+ fn test_extract_var_path_simple ( ) {
365365 check_assist (
366- introduce_variable ,
366+ extract_variable ,
367367 "
368368fn main() {
369369 let o = <|>Some(true)<|>;
@@ -379,9 +379,9 @@ fn main() {
379379 }
380380
381381 #[ test]
382- fn test_introduce_var_path_method ( ) {
382+ fn test_extract_var_path_method ( ) {
383383 check_assist (
384- introduce_variable ,
384+ extract_variable ,
385385 "
386386fn main() {
387387 let v = <|>bar.foo()<|>;
@@ -397,9 +397,9 @@ fn main() {
397397 }
398398
399399 #[ test]
400- fn test_introduce_var_return ( ) {
400+ fn test_extract_var_return ( ) {
401401 check_assist (
402- introduce_variable ,
402+ extract_variable ,
403403 "
404404fn foo() -> u32 {
405405 <|>return 2 + 2<|>;
@@ -415,9 +415,9 @@ fn foo() -> u32 {
415415 }
416416
417417 #[ test]
418- fn test_introduce_var_does_not_add_extra_whitespace ( ) {
418+ fn test_extract_var_does_not_add_extra_whitespace ( ) {
419419 check_assist (
420- introduce_variable ,
420+ extract_variable ,
421421 "
422422fn foo() -> u32 {
423423
@@ -436,7 +436,7 @@ fn foo() -> u32 {
436436 ) ;
437437
438438 check_assist (
439- introduce_variable ,
439+ extract_variable ,
440440 "
441441fn foo() -> u32 {
442442
@@ -453,7 +453,7 @@ fn foo() -> u32 {
453453 ) ;
454454
455455 check_assist (
456- introduce_variable ,
456+ extract_variable ,
457457 "
458458fn foo() -> u32 {
459459 let foo = 1;
@@ -479,9 +479,9 @@ fn foo() -> u32 {
479479 }
480480
481481 #[ test]
482- fn test_introduce_var_break ( ) {
482+ fn test_extract_var_break ( ) {
483483 check_assist (
484- introduce_variable ,
484+ extract_variable ,
485485 "
486486fn main() {
487487 let result = loop {
@@ -501,9 +501,9 @@ fn main() {
501501 }
502502
503503 #[ test]
504- fn test_introduce_var_for_cast ( ) {
504+ fn test_extract_var_for_cast ( ) {
505505 check_assist (
506- introduce_variable ,
506+ extract_variable ,
507507 "
508508fn main() {
509509 let v = <|>0f32 as u32<|>;
@@ -519,9 +519,9 @@ fn main() {
519519 }
520520
521521 #[ test]
522- fn introduce_var_field_shorthand ( ) {
522+ fn extract_var_field_shorthand ( ) {
523523 check_assist (
524- introduce_variable ,
524+ extract_variable ,
525525 r#"
526526struct S {
527527 foo: i32
@@ -545,22 +545,22 @@ fn main() {
545545 }
546546
547547 #[ 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<|>; } " ) ;
550550 }
551551
552552 #[ 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<|>; }; }" ) ;
555555 }
556556
557557 // FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic
558558 #[ 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" ) ;
561561
562562 check_assist_target (
563- introduce_variable ,
563+ extract_variable ,
564564 "
565565fn main() {
566566 let x = true;
0 commit comments