aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/release.yaml2
-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.rs8
-rw-r--r--crates/assists/src/tests/generated.rs58
-rw-r--r--editors/code/src/main.ts19
5 files changed, 70 insertions, 71 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index cc39943ab..fd22ea88a 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -45,7 +45,7 @@ jobs:
45 - name: Upload artifacts 45 - name: Upload artifacts
46 uses: actions/upload-artifact@v1 46 uses: actions/upload-artifact@v1
47 with: 47 with:
48 name: x86_64-pc-windows-msvc 48 name: dist-x86_64-pc-windows-msvc
49 path: ./dist 49 path: ./dist
50 50
51 dist-aarch64-pc-windows-msvc: 51 dist-aarch64-pc-windows-msvc:
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// ```
39pub(crate) fn extract_assigment(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 39pub(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#"
174fn foo() { 174fn 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#"
201fn foo() { 201fn 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#"
240fn foo() { 240fn 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#"
259fn foo() { 259fn 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#"
290fn foo() { 290fn 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#"
321fn foo() { 321fn 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#"
338fn foo() { 338fn 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#"
353fn foo() { 353fn 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#"
375struct A(usize); 375struct 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]
241fn doctest_extract_assignment() {
242 check_doc_test(
243 "extract_assignment",
244 r#####"
245fn main() {
246 let mut foo = 6;
247
248 if true {
249 <|>foo = 5;
250 } else {
251 foo = 4;
252 }
253}
254"#####,
255 r#####"
256fn 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]
270fn doctest_extract_module_to_file() { 241fn 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]
741fn doctest_pull_assignment_up() {
742 check_doc_test(
743 "pull_assignment_up",
744 r#####"
745fn main() {
746 let mut foo = 6;
747
748 if true {
749 <|>foo = 5;
750 } else {
751 foo = 4;
752 }
753}
754"#####,
755 r#####"
756fn 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]
770fn doctest_qualify_path() { 770fn doctest_qualify_path() {
771 check_doc_test( 771 check_doc_test(
772 "qualify_path", 772 "qualify_path",
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 60907dfd4..4c132cabe 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -287,16 +287,15 @@ async function getServer(config: Config, state: PersistentState): Promise<string
287 }; 287 };
288 if (config.package.releaseTag === null) return "rust-analyzer"; 288 if (config.package.releaseTag === null) return "rust-analyzer";
289 289
290 let platform: string | undefined; 290 const platforms: { [key: string]: string } = {
291 if ((process.arch === "x64" || process.arch === "ia32") && process.platform === "win32") { 291 "ia32 win32": "x86_64-pc-windows-msvc",
292 platform = "x86_64-pc-windows-msvc"; 292 "x64 win32": "x86_64-pc-windows-msvc",
293 } else if (process.arch === "x64" && process.platform === "linux") { 293 "x64 linux": "x86_64-unknown-linux-gnu",
294 platform = "x86_64-unknown-linux-gnu"; 294 "x64 darwin": "x86_64-apple-darwin",
295 } else if (process.arch === "x64" && process.platform === "darwin") { 295 "arm64 win32": "aarch64-pc-windows-msvc",
296 platform = "x86_64-apple-darwin"; 296 "arm64 darwin": "aarch64-apple-darwin",
297 } else if (process.arch === "arm64" && process.platform === "darwin") { 297 };
298 platform = "aarch64-apple-darwin"; 298 const platform = platforms[`${process.arch} ${process.platform}`];
299 }
300 if (platform === undefined) { 299 if (platform === undefined) {
301 vscode.window.showErrorMessage( 300 vscode.window.showErrorMessage(
302 "Unfortunately we don't ship binaries for your platform yet. " + 301 "Unfortunately we don't ship binaries for your platform yet. " +