diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-04 14:47:16 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-04 14:47:16 +0000 |
commit | 484df745cc4885a5f05ce7a5d5d1be4215bcb5d3 (patch) | |
tree | 53b7010c37ba4e6ec5332e345bef170533099c2f /crates | |
parent | dcb5387b420456d6cb827a90756931ada70f4e6a (diff) | |
parent | 46afdb6e9b50f1493ca92905fa4ae858fb496c7a (diff) |
Merge #7153
7153: rename exrtract_assignment -> pull r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/assists/src/handlers/pull_assignment_up.rs (renamed from crates/assists/src/handlers/extract_assignment.rs) | 54 | ||||
-rw-r--r-- | crates/assists/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/assists/src/tests/generated.rs | 58 |
3 files changed, 60 insertions, 60 deletions
diff --git a/crates/assists/src/handlers/extract_assignment.rs b/crates/assists/src/handlers/pull_assignment_up.rs index ae99598c0..560d93e10 100644 --- a/crates/assists/src/handlers/extract_assignment.rs +++ b/crates/assists/src/handlers/pull_assignment_up.rs | |||
@@ -9,9 +9,9 @@ use crate::{ | |||
9 | AssistId, AssistKind, | 9 | AssistId, AssistKind, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | // Assist: extract_assignment | 12 | // Assist: pull_assignment_up |
13 | // | 13 | // |
14 | // Extracts variable assigment to outside an if or match statement. | 14 | // Extracts variable assignment to outside an if or match statement. |
15 | // | 15 | // |
16 | // ``` | 16 | // ``` |
17 | // fn main() { | 17 | // fn main() { |
@@ -36,7 +36,7 @@ use crate::{ | |||
36 | // }; | 36 | // }; |
37 | // } | 37 | // } |
38 | // ``` | 38 | // ``` |
39 | pub(crate) fn extract_assigment(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 39 | pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
40 | let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?; | 40 | let assign_expr = ctx.find_node_at_offset::<ast::BinExpr>()?; |
41 | let name_expr = if assign_expr.op_kind()? == ast::BinOp::Assignment { | 41 | let name_expr = if assign_expr.op_kind()? == ast::BinOp::Assignment { |
42 | assign_expr.lhs()? | 42 | assign_expr.lhs()? |
@@ -61,8 +61,8 @@ pub(crate) fn extract_assigment(acc: &mut Assists, ctx: &AssistContext) -> Optio | |||
61 | let expr_stmt = make::expr_stmt(new_stmt); | 61 | let expr_stmt = make::expr_stmt(new_stmt); |
62 | 62 | ||
63 | acc.add( | 63 | acc.add( |
64 | AssistId("extract_assignment", AssistKind::RefactorExtract), | 64 | AssistId("pull_assignment_up", AssistKind::RefactorExtract), |
65 | "Extract assignment", | 65 | "Pull assignment up", |
66 | old_stmt.syntax().text_range(), | 66 | old_stmt.syntax().text_range(), |
67 | move |edit| { | 67 | move |edit| { |
68 | edit.replace(old_stmt.syntax().text_range(), format!("{} = {};", name_expr, expr_stmt)); | 68 | edit.replace(old_stmt.syntax().text_range(), format!("{} = {};", name_expr, expr_stmt)); |
@@ -104,7 +104,7 @@ fn exprify_if( | |||
104 | ast::ElseBranch::Block(exprify_block(block, sema, name)?) | 104 | ast::ElseBranch::Block(exprify_block(block, sema, name)?) |
105 | } | 105 | } |
106 | ast::ElseBranch::IfExpr(expr) => { | 106 | ast::ElseBranch::IfExpr(expr) => { |
107 | mark::hit!(test_extract_assigment_chained_if); | 107 | mark::hit!(test_pull_assignment_up_chained_if); |
108 | ast::ElseBranch::IfExpr(ast::IfExpr::cast( | 108 | ast::ElseBranch::IfExpr(ast::IfExpr::cast( |
109 | exprify_if(&expr, sema, name)?.syntax().to_owned(), | 109 | exprify_if(&expr, sema, name)?.syntax().to_owned(), |
110 | )?) | 110 | )?) |
@@ -144,7 +144,7 @@ fn is_equivalent( | |||
144 | ) -> bool { | 144 | ) -> bool { |
145 | match (expr0, expr1) { | 145 | match (expr0, expr1) { |
146 | (ast::Expr::FieldExpr(field_expr0), ast::Expr::FieldExpr(field_expr1)) => { | 146 | (ast::Expr::FieldExpr(field_expr0), ast::Expr::FieldExpr(field_expr1)) => { |
147 | mark::hit!(test_extract_assignment_field_assignment); | 147 | mark::hit!(test_pull_assignment_up_field_assignment); |
148 | sema.resolve_field(field_expr0) == sema.resolve_field(field_expr1) | 148 | sema.resolve_field(field_expr0) == sema.resolve_field(field_expr1) |
149 | } | 149 | } |
150 | (ast::Expr::PathExpr(path0), ast::Expr::PathExpr(path1)) => { | 150 | (ast::Expr::PathExpr(path0), ast::Expr::PathExpr(path1)) => { |
@@ -167,9 +167,9 @@ mod tests { | |||
167 | use crate::tests::{check_assist, check_assist_not_applicable}; | 167 | use crate::tests::{check_assist, check_assist_not_applicable}; |
168 | 168 | ||
169 | #[test] | 169 | #[test] |
170 | fn test_extract_assignment_if() { | 170 | fn test_pull_assignment_up_if() { |
171 | check_assist( | 171 | check_assist( |
172 | extract_assigment, | 172 | pull_assignment_up, |
173 | r#" | 173 | r#" |
174 | fn foo() { | 174 | fn foo() { |
175 | let mut a = 1; | 175 | let mut a = 1; |
@@ -194,9 +194,9 @@ fn foo() { | |||
194 | } | 194 | } |
195 | 195 | ||
196 | #[test] | 196 | #[test] |
197 | fn test_extract_assignment_match() { | 197 | fn test_pull_assignment_up_match() { |
198 | check_assist( | 198 | check_assist( |
199 | extract_assigment, | 199 | pull_assignment_up, |
200 | r#" | 200 | r#" |
201 | fn foo() { | 201 | fn foo() { |
202 | let mut a = 1; | 202 | let mut a = 1; |
@@ -233,9 +233,9 @@ fn foo() { | |||
233 | } | 233 | } |
234 | 234 | ||
235 | #[test] | 235 | #[test] |
236 | fn test_extract_assignment_not_last_not_applicable() { | 236 | fn test_pull_assignment_up_not_last_not_applicable() { |
237 | check_assist_not_applicable( | 237 | check_assist_not_applicable( |
238 | extract_assigment, | 238 | pull_assignment_up, |
239 | r#" | 239 | r#" |
240 | fn foo() { | 240 | fn foo() { |
241 | let mut a = 1; | 241 | let mut a = 1; |
@@ -251,10 +251,10 @@ fn foo() { | |||
251 | } | 251 | } |
252 | 252 | ||
253 | #[test] | 253 | #[test] |
254 | fn test_extract_assignment_chained_if() { | 254 | fn test_pull_assignment_up_chained_if() { |
255 | mark::check!(test_extract_assigment_chained_if); | 255 | mark::check!(test_pull_assignment_up_chained_if); |
256 | check_assist( | 256 | check_assist( |
257 | extract_assigment, | 257 | pull_assignment_up, |
258 | r#" | 258 | r#" |
259 | fn foo() { | 259 | fn foo() { |
260 | let mut a = 1; | 260 | let mut a = 1; |
@@ -283,9 +283,9 @@ fn foo() { | |||
283 | } | 283 | } |
284 | 284 | ||
285 | #[test] | 285 | #[test] |
286 | fn test_extract_assigment_retains_stmts() { | 286 | fn test_pull_assignment_up_retains_stmts() { |
287 | check_assist( | 287 | check_assist( |
288 | extract_assigment, | 288 | pull_assignment_up, |
289 | r#" | 289 | r#" |
290 | fn foo() { | 290 | fn foo() { |
291 | let mut a = 1; | 291 | let mut a = 1; |
@@ -314,9 +314,9 @@ fn foo() { | |||
314 | } | 314 | } |
315 | 315 | ||
316 | #[test] | 316 | #[test] |
317 | fn extract_assignment_let_stmt_not_applicable() { | 317 | fn pull_assignment_up_let_stmt_not_applicable() { |
318 | check_assist_not_applicable( | 318 | check_assist_not_applicable( |
319 | extract_assigment, | 319 | pull_assignment_up, |
320 | r#" | 320 | r#" |
321 | fn foo() { | 321 | fn foo() { |
322 | let mut a = 1; | 322 | let mut a = 1; |
@@ -331,9 +331,9 @@ fn foo() { | |||
331 | } | 331 | } |
332 | 332 | ||
333 | #[test] | 333 | #[test] |
334 | fn extract_assignment_if_missing_assigment_not_applicable() { | 334 | fn pull_assignment_up_if_missing_assigment_not_applicable() { |
335 | check_assist_not_applicable( | 335 | check_assist_not_applicable( |
336 | extract_assigment, | 336 | pull_assignment_up, |
337 | r#" | 337 | r#" |
338 | fn foo() { | 338 | fn foo() { |
339 | let mut a = 1; | 339 | let mut a = 1; |
@@ -346,9 +346,9 @@ fn foo() { | |||
346 | } | 346 | } |
347 | 347 | ||
348 | #[test] | 348 | #[test] |
349 | fn extract_assignment_match_missing_assigment_not_applicable() { | 349 | fn pull_assignment_up_match_missing_assigment_not_applicable() { |
350 | check_assist_not_applicable( | 350 | check_assist_not_applicable( |
351 | extract_assigment, | 351 | pull_assignment_up, |
352 | r#" | 352 | r#" |
353 | fn foo() { | 353 | fn foo() { |
354 | let mut a = 1; | 354 | let mut a = 1; |
@@ -367,10 +367,10 @@ fn foo() { | |||
367 | } | 367 | } |
368 | 368 | ||
369 | #[test] | 369 | #[test] |
370 | fn test_extract_assignment_field_assignment() { | 370 | fn test_pull_assignment_up_field_assignment() { |
371 | mark::check!(test_extract_assignment_field_assignment); | 371 | mark::check!(test_pull_assignment_up_field_assignment); |
372 | check_assist( | 372 | check_assist( |
373 | extract_assigment, | 373 | pull_assignment_up, |
374 | r#" | 374 | r#" |
375 | struct A(usize); | 375 | struct A(usize); |
376 | 376 | ||
diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs index 212464f85..01baa65fe 100644 --- a/crates/assists/src/lib.rs +++ b/crates/assists/src/lib.rs | |||
@@ -116,7 +116,6 @@ mod handlers { | |||
116 | mod convert_integer_literal; | 116 | mod convert_integer_literal; |
117 | mod early_return; | 117 | mod early_return; |
118 | mod expand_glob_import; | 118 | mod expand_glob_import; |
119 | mod extract_assignment; | ||
120 | mod extract_module_to_file; | 119 | mod extract_module_to_file; |
121 | mod extract_struct_from_enum_variant; | 120 | mod extract_struct_from_enum_variant; |
122 | mod extract_variable; | 121 | mod extract_variable; |
@@ -125,8 +124,8 @@ mod handlers { | |||
125 | mod flip_binexpr; | 124 | mod flip_binexpr; |
126 | mod flip_comma; | 125 | mod flip_comma; |
127 | mod flip_trait_bound; | 126 | mod flip_trait_bound; |
128 | mod generate_derive; | ||
129 | mod generate_default_from_enum_variant; | 127 | mod generate_default_from_enum_variant; |
128 | mod generate_derive; | ||
130 | mod generate_from_impl_for_enum; | 129 | mod generate_from_impl_for_enum; |
131 | mod generate_function; | 130 | mod generate_function; |
132 | mod generate_impl; | 131 | mod generate_impl; |
@@ -139,6 +138,7 @@ mod handlers { | |||
139 | mod merge_match_arms; | 138 | mod merge_match_arms; |
140 | mod move_bounds; | 139 | mod move_bounds; |
141 | mod move_guard; | 140 | mod move_guard; |
141 | mod pull_assignment_up; | ||
142 | mod qualify_path; | 142 | mod qualify_path; |
143 | mod raw_string; | 143 | mod raw_string; |
144 | mod remove_dbg; | 144 | mod remove_dbg; |
@@ -168,7 +168,6 @@ mod handlers { | |||
168 | convert_integer_literal::convert_integer_literal, | 168 | convert_integer_literal::convert_integer_literal, |
169 | early_return::convert_to_guarded_return, | 169 | early_return::convert_to_guarded_return, |
170 | expand_glob_import::expand_glob_import, | 170 | expand_glob_import::expand_glob_import, |
171 | extract_assignment::extract_assigment, | ||
172 | extract_module_to_file::extract_module_to_file, | 171 | extract_module_to_file::extract_module_to_file, |
173 | extract_struct_from_enum_variant::extract_struct_from_enum_variant, | 172 | extract_struct_from_enum_variant::extract_struct_from_enum_variant, |
174 | extract_variable::extract_variable, | 173 | extract_variable::extract_variable, |
@@ -177,8 +176,8 @@ mod handlers { | |||
177 | flip_binexpr::flip_binexpr, | 176 | flip_binexpr::flip_binexpr, |
178 | flip_comma::flip_comma, | 177 | flip_comma::flip_comma, |
179 | flip_trait_bound::flip_trait_bound, | 178 | flip_trait_bound::flip_trait_bound, |
180 | generate_derive::generate_derive, | ||
181 | generate_default_from_enum_variant::generate_default_from_enum_variant, | 179 | generate_default_from_enum_variant::generate_default_from_enum_variant, |
180 | generate_derive::generate_derive, | ||
182 | generate_from_impl_for_enum::generate_from_impl_for_enum, | 181 | generate_from_impl_for_enum::generate_from_impl_for_enum, |
183 | generate_function::generate_function, | 182 | generate_function::generate_function, |
184 | generate_impl::generate_impl, | 183 | generate_impl::generate_impl, |
@@ -192,6 +191,7 @@ mod handlers { | |||
192 | move_bounds::move_bounds_to_where_clause, | 191 | move_bounds::move_bounds_to_where_clause, |
193 | move_guard::move_arm_cond_to_match_guard, | 192 | move_guard::move_arm_cond_to_match_guard, |
194 | move_guard::move_guard_to_arm_body, | 193 | move_guard::move_guard_to_arm_body, |
194 | pull_assignment_up::pull_assignment_up, | ||
195 | qualify_path::qualify_path, | 195 | qualify_path::qualify_path, |
196 | raw_string::add_hash, | 196 | raw_string::add_hash, |
197 | raw_string::make_usual_string, | 197 | raw_string::make_usual_string, |
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index b91a816e8..85e3c6742 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs | |||
@@ -238,35 +238,6 @@ fn qux(bar: Bar, baz: Baz) {} | |||
238 | } | 238 | } |
239 | 239 | ||
240 | #[test] | 240 | #[test] |
241 | fn doctest_extract_assignment() { | ||
242 | check_doc_test( | ||
243 | "extract_assignment", | ||
244 | r#####" | ||
245 | fn main() { | ||
246 | let mut foo = 6; | ||
247 | |||
248 | if true { | ||
249 | <|>foo = 5; | ||
250 | } else { | ||
251 | foo = 4; | ||
252 | } | ||
253 | } | ||
254 | "#####, | ||
255 | r#####" | ||
256 | fn main() { | ||
257 | let mut foo = 6; | ||
258 | |||
259 | foo = if true { | ||
260 | 5 | ||
261 | } else { | ||
262 | 4 | ||
263 | }; | ||
264 | } | ||
265 | "#####, | ||
266 | ) | ||
267 | } | ||
268 | |||
269 | #[test] | ||
270 | fn doctest_extract_module_to_file() { | 241 | fn doctest_extract_module_to_file() { |
271 | check_doc_test( | 242 | check_doc_test( |
272 | "extract_module_to_file", | 243 | "extract_module_to_file", |
@@ -767,6 +738,35 @@ fn handle(action: Action) { | |||
767 | } | 738 | } |
768 | 739 | ||
769 | #[test] | 740 | #[test] |
741 | fn doctest_pull_assignment_up() { | ||
742 | check_doc_test( | ||
743 | "pull_assignment_up", | ||
744 | r#####" | ||
745 | fn main() { | ||
746 | let mut foo = 6; | ||
747 | |||
748 | if true { | ||
749 | <|>foo = 5; | ||
750 | } else { | ||
751 | foo = 4; | ||
752 | } | ||
753 | } | ||
754 | "#####, | ||
755 | r#####" | ||
756 | fn main() { | ||
757 | let mut foo = 6; | ||
758 | |||
759 | foo = if true { | ||
760 | 5 | ||
761 | } else { | ||
762 | 4 | ||
763 | }; | ||
764 | } | ||
765 | "#####, | ||
766 | ) | ||
767 | } | ||
768 | |||
769 | #[test] | ||
770 | fn doctest_qualify_path() { | 770 | fn doctest_qualify_path() { |
771 | check_doc_test( | 771 | check_doc_test( |
772 | "qualify_path", | 772 | "qualify_path", |