diff options
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/add_explicit_type.rs | 26 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/auto_import.rs | 222 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/inline_local_variable.rs | 65 |
3 files changed, 287 insertions, 26 deletions
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs index f9f826b88..38a351a54 100644 --- a/crates/ra_assists/src/assists/add_explicit_type.rs +++ b/crates/ra_assists/src/assists/add_explicit_type.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use hir::{db::HirDatabase, HirDisplay}; | 1 | use hir::{db::HirDatabase, HirDisplay}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode, LetStmt, NameOwner}, | 3 | ast::{self, AstNode, LetStmt, NameOwner}, |
4 | T, | 4 | TextRange, T, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use crate::{Assist, AssistCtx, AssistId}; | 7 | use crate::{Assist, AssistCtx, AssistId}; |
@@ -34,6 +34,14 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx<impl HirDatabase>) -> Option<Assi | |||
34 | // The binding must have a name | 34 | // The binding must have a name |
35 | let name = pat.name()?; | 35 | let name = pat.name()?; |
36 | let name_range = name.syntax().text_range(); | 36 | let name_range = name.syntax().text_range(); |
37 | // Assist should only be applicable if cursor is between 'let' and '=' | ||
38 | let stmt_range = stmt.syntax().text_range(); | ||
39 | let eq_range = stmt.eq_token()?.text_range(); | ||
40 | let let_range = TextRange::from_to(stmt_range.start(), eq_range.start()); | ||
41 | let cursor_in_range = ctx.frange.range.is_subrange(&let_range); | ||
42 | if !cursor_in_range { | ||
43 | return None; | ||
44 | } | ||
37 | // Assist not applicable if the type has already been specified | 45 | // Assist not applicable if the type has already been specified |
38 | if stmt.syntax().children_with_tokens().any(|child| child.kind() == T![:]) { | 46 | if stmt.syntax().children_with_tokens().any(|child| child.kind() == T![:]) { |
39 | return None; | 47 | return None; |
@@ -109,4 +117,20 @@ mod tests { | |||
109 | fn add_explicit_type_not_applicable_if_specified_ty_is_tuple() { | 117 | fn add_explicit_type_not_applicable_if_specified_ty_is_tuple() { |
110 | check_assist_not_applicable(add_explicit_type, "fn f() { let a<|>: (i32, i32) = (3, 4); }"); | 118 | check_assist_not_applicable(add_explicit_type, "fn f() { let a<|>: (i32, i32) = (3, 4); }"); |
111 | } | 119 | } |
120 | |||
121 | #[test] | ||
122 | fn add_explicit_type_not_applicable_if_cursor_after_equals() { | ||
123 | check_assist_not_applicable( | ||
124 | add_explicit_type, | ||
125 | "fn f() {let a =<|> match 1 {2 => 3, 3 => 5};}", | ||
126 | ) | ||
127 | } | ||
128 | |||
129 | #[test] | ||
130 | fn add_explicit_type_not_applicable_if_cursor_before_let() { | ||
131 | check_assist_not_applicable( | ||
132 | add_explicit_type, | ||
133 | "fn f() <|>{let a = match 1 {2 => 3, 3 => 5};}", | ||
134 | ) | ||
135 | } | ||
112 | } | 136 | } |
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs new file mode 100644 index 000000000..9163cc662 --- /dev/null +++ b/crates/ra_assists/src/assists/auto_import.rs | |||
@@ -0,0 +1,222 @@ | |||
1 | use hir::db::HirDatabase; | ||
2 | use ra_syntax::{ | ||
3 | ast::{self, AstNode}, | ||
4 | SmolStr, SyntaxElement, | ||
5 | SyntaxKind::{NAME_REF, USE_ITEM}, | ||
6 | SyntaxNode, | ||
7 | }; | ||
8 | |||
9 | use crate::{ | ||
10 | assist_ctx::{ActionBuilder, Assist, AssistCtx}, | ||
11 | auto_import_text_edit, AssistId, ImportsLocator, | ||
12 | }; | ||
13 | |||
14 | // Assist: auto_import | ||
15 | // | ||
16 | // If the name is unresolved, provides all possible imports for it. | ||
17 | // | ||
18 | // ``` | ||
19 | // fn main() { | ||
20 | // let map = HashMap<|>::new(); | ||
21 | // } | ||
22 | // ``` | ||
23 | // -> | ||
24 | // ``` | ||
25 | // use std::collections::HashMap; | ||
26 | // | ||
27 | // fn main() { | ||
28 | // let map = HashMap<|>::new(); | ||
29 | // } | ||
30 | // ``` | ||
31 | pub(crate) fn auto_import<F: ImportsLocator>( | ||
32 | ctx: AssistCtx<impl HirDatabase>, | ||
33 | imports_locator: &mut F, | ||
34 | ) -> Option<Assist> { | ||
35 | let path: ast::Path = ctx.find_node_at_offset()?; | ||
36 | let module = path.syntax().ancestors().find_map(ast::Module::cast); | ||
37 | let position = match module.and_then(|it| it.item_list()) { | ||
38 | Some(item_list) => item_list.syntax().clone(), | ||
39 | None => { | ||
40 | let current_file = path.syntax().ancestors().find_map(ast::SourceFile::cast)?; | ||
41 | current_file.syntax().clone() | ||
42 | } | ||
43 | }; | ||
44 | let source_analyzer = ctx.source_analyzer(&position, None); | ||
45 | let module_with_name_to_import = source_analyzer.module()?; | ||
46 | let path_to_import = ctx.covering_element().ancestors().find_map(ast::Path::cast)?; | ||
47 | if source_analyzer.resolve_path(ctx.db, &path_to_import).is_some() { | ||
48 | return None; | ||
49 | } | ||
50 | |||
51 | let name_to_import = &find_applicable_name_ref(ctx.covering_element())?.syntax().to_string(); | ||
52 | let proposed_imports = imports_locator | ||
53 | .find_imports(&name_to_import.to_string()) | ||
54 | .into_iter() | ||
55 | .filter_map(|module_def| module_with_name_to_import.find_use_path(ctx.db, module_def)) | ||
56 | .filter(|use_path| !use_path.segments.is_empty()) | ||
57 | .take(20) | ||
58 | .map(|import| import.to_string()) | ||
59 | .collect::<std::collections::BTreeSet<_>>(); | ||
60 | if proposed_imports.is_empty() { | ||
61 | return None; | ||
62 | } | ||
63 | |||
64 | ctx.add_assist_group(AssistId("auto_import"), "auto import", || { | ||
65 | proposed_imports | ||
66 | .into_iter() | ||
67 | .map(|import| import_to_action(import, &position, &path_to_import.syntax())) | ||
68 | .collect() | ||
69 | }) | ||
70 | } | ||
71 | |||
72 | fn find_applicable_name_ref(element: SyntaxElement) -> Option<ast::NameRef> { | ||
73 | if element.ancestors().find(|ancestor| ancestor.kind() == USE_ITEM).is_some() { | ||
74 | None | ||
75 | } else if element.kind() == NAME_REF { | ||
76 | Some(element.as_node().cloned().and_then(ast::NameRef::cast)?) | ||
77 | } else { | ||
78 | let parent = element.parent()?; | ||
79 | if parent.kind() == NAME_REF { | ||
80 | Some(ast::NameRef::cast(parent)?) | ||
81 | } else { | ||
82 | None | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { | ||
88 | let mut action_builder = ActionBuilder::default(); | ||
89 | action_builder.label(format!("Import `{}`", &import)); | ||
90 | auto_import_text_edit( | ||
91 | position, | ||
92 | anchor, | ||
93 | &[SmolStr::new(import)], | ||
94 | action_builder.text_edit_builder(), | ||
95 | ); | ||
96 | action_builder | ||
97 | } | ||
98 | |||
99 | #[cfg(test)] | ||
100 | mod tests { | ||
101 | use super::*; | ||
102 | use crate::helpers::{ | ||
103 | check_assist_with_imports_locator, check_assist_with_imports_locator_not_applicable, | ||
104 | TestImportsLocator, | ||
105 | }; | ||
106 | |||
107 | #[test] | ||
108 | fn applicable_when_found_an_import() { | ||
109 | check_assist_with_imports_locator( | ||
110 | auto_import, | ||
111 | TestImportsLocator::new, | ||
112 | r" | ||
113 | PubStruct<|> | ||
114 | |||
115 | pub mod PubMod { | ||
116 | pub struct PubStruct; | ||
117 | } | ||
118 | ", | ||
119 | r" | ||
120 | use PubMod::PubStruct; | ||
121 | |||
122 | PubStruct<|> | ||
123 | |||
124 | pub mod PubMod { | ||
125 | pub struct PubStruct; | ||
126 | } | ||
127 | ", | ||
128 | ); | ||
129 | } | ||
130 | |||
131 | #[test] | ||
132 | fn applicable_when_found_multiple_imports() { | ||
133 | check_assist_with_imports_locator( | ||
134 | auto_import, | ||
135 | TestImportsLocator::new, | ||
136 | r" | ||
137 | PubStruct<|> | ||
138 | |||
139 | pub mod PubMod1 { | ||
140 | pub struct PubStruct; | ||
141 | } | ||
142 | pub mod PubMod2 { | ||
143 | pub struct PubStruct; | ||
144 | } | ||
145 | pub mod PubMod3 { | ||
146 | pub struct PubStruct; | ||
147 | } | ||
148 | ", | ||
149 | r" | ||
150 | use PubMod1::PubStruct; | ||
151 | |||
152 | PubStruct<|> | ||
153 | |||
154 | pub mod PubMod1 { | ||
155 | pub struct PubStruct; | ||
156 | } | ||
157 | pub mod PubMod2 { | ||
158 | pub struct PubStruct; | ||
159 | } | ||
160 | pub mod PubMod3 { | ||
161 | pub struct PubStruct; | ||
162 | } | ||
163 | ", | ||
164 | ); | ||
165 | } | ||
166 | |||
167 | #[test] | ||
168 | fn not_applicable_for_already_imported_types() { | ||
169 | check_assist_with_imports_locator_not_applicable( | ||
170 | auto_import, | ||
171 | TestImportsLocator::new, | ||
172 | r" | ||
173 | use PubMod::PubStruct; | ||
174 | |||
175 | PubStruct<|> | ||
176 | |||
177 | pub mod PubMod { | ||
178 | pub struct PubStruct; | ||
179 | } | ||
180 | ", | ||
181 | ); | ||
182 | } | ||
183 | |||
184 | #[test] | ||
185 | fn not_applicable_for_types_with_private_paths() { | ||
186 | check_assist_with_imports_locator_not_applicable( | ||
187 | auto_import, | ||
188 | TestImportsLocator::new, | ||
189 | r" | ||
190 | PrivateStruct<|> | ||
191 | |||
192 | pub mod PubMod { | ||
193 | struct PrivateStruct; | ||
194 | } | ||
195 | ", | ||
196 | ); | ||
197 | } | ||
198 | |||
199 | #[test] | ||
200 | fn not_applicable_when_no_imports_found() { | ||
201 | check_assist_with_imports_locator_not_applicable( | ||
202 | auto_import, | ||
203 | TestImportsLocator::new, | ||
204 | " | ||
205 | PubStruct<|>", | ||
206 | ); | ||
207 | } | ||
208 | |||
209 | #[test] | ||
210 | fn not_applicable_in_import_statements() { | ||
211 | check_assist_with_imports_locator_not_applicable( | ||
212 | auto_import, | ||
213 | TestImportsLocator::new, | ||
214 | r" | ||
215 | use PubStruct<|>; | ||
216 | |||
217 | pub mod PubMod { | ||
218 | pub struct PubStruct; | ||
219 | }", | ||
220 | ); | ||
221 | } | ||
222 | } | ||
diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index 45e0f983f..83527d904 100644 --- a/crates/ra_assists/src/assists/inline_local_variable.rs +++ b/crates/ra_assists/src/assists/inline_local_variable.rs | |||
@@ -23,7 +23,7 @@ use crate::{Assist, AssistCtx, AssistId}; | |||
23 | // (1 + 2) * 4; | 23 | // (1 + 2) * 4; |
24 | // } | 24 | // } |
25 | // ``` | 25 | // ``` |
26 | pub(crate) fn inline_local_varialbe(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 26 | pub(crate) fn inline_local_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
27 | let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?; | 27 | let let_stmt = ctx.find_node_at_offset::<ast::LetStmt>()?; |
28 | let bind_pat = match let_stmt.pat()? { | 28 | let bind_pat = match let_stmt.pat()? { |
29 | ast::Pat::BindPat(pat) => pat, | 29 | ast::Pat::BindPat(pat) => pat, |
@@ -47,6 +47,9 @@ pub(crate) fn inline_local_varialbe(ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
47 | }; | 47 | }; |
48 | let analyzer = ctx.source_analyzer(bind_pat.syntax(), None); | 48 | let analyzer = ctx.source_analyzer(bind_pat.syntax(), None); |
49 | let refs = analyzer.find_all_refs(&bind_pat); | 49 | let refs = analyzer.find_all_refs(&bind_pat); |
50 | if refs.is_empty() { | ||
51 | return None; | ||
52 | }; | ||
50 | 53 | ||
51 | let mut wrap_in_parens = vec![true; refs.len()]; | 54 | let mut wrap_in_parens = vec![true; refs.len()]; |
52 | 55 | ||
@@ -117,7 +120,7 @@ mod tests { | |||
117 | #[test] | 120 | #[test] |
118 | fn test_inline_let_bind_literal_expr() { | 121 | fn test_inline_let_bind_literal_expr() { |
119 | check_assist( | 122 | check_assist( |
120 | inline_local_varialbe, | 123 | inline_local_variable, |
121 | " | 124 | " |
122 | fn bar(a: usize) {} | 125 | fn bar(a: usize) {} |
123 | fn foo() { | 126 | fn foo() { |
@@ -151,7 +154,7 @@ fn foo() { | |||
151 | #[test] | 154 | #[test] |
152 | fn test_inline_let_bind_bin_expr() { | 155 | fn test_inline_let_bind_bin_expr() { |
153 | check_assist( | 156 | check_assist( |
154 | inline_local_varialbe, | 157 | inline_local_variable, |
155 | " | 158 | " |
156 | fn bar(a: usize) {} | 159 | fn bar(a: usize) {} |
157 | fn foo() { | 160 | fn foo() { |
@@ -185,7 +188,7 @@ fn foo() { | |||
185 | #[test] | 188 | #[test] |
186 | fn test_inline_let_bind_function_call_expr() { | 189 | fn test_inline_let_bind_function_call_expr() { |
187 | check_assist( | 190 | check_assist( |
188 | inline_local_varialbe, | 191 | inline_local_variable, |
189 | " | 192 | " |
190 | fn bar(a: usize) {} | 193 | fn bar(a: usize) {} |
191 | fn foo() { | 194 | fn foo() { |
@@ -219,7 +222,7 @@ fn foo() { | |||
219 | #[test] | 222 | #[test] |
220 | fn test_inline_let_bind_cast_expr() { | 223 | fn test_inline_let_bind_cast_expr() { |
221 | check_assist( | 224 | check_assist( |
222 | inline_local_varialbe, | 225 | inline_local_variable, |
223 | " | 226 | " |
224 | fn bar(a: usize): usize { a } | 227 | fn bar(a: usize): usize { a } |
225 | fn foo() { | 228 | fn foo() { |
@@ -253,7 +256,7 @@ fn foo() { | |||
253 | #[test] | 256 | #[test] |
254 | fn test_inline_let_bind_block_expr() { | 257 | fn test_inline_let_bind_block_expr() { |
255 | check_assist( | 258 | check_assist( |
256 | inline_local_varialbe, | 259 | inline_local_variable, |
257 | " | 260 | " |
258 | fn foo() { | 261 | fn foo() { |
259 | let a<|> = { 10 + 1 }; | 262 | let a<|> = { 10 + 1 }; |
@@ -285,7 +288,7 @@ fn foo() { | |||
285 | #[test] | 288 | #[test] |
286 | fn test_inline_let_bind_paren_expr() { | 289 | fn test_inline_let_bind_paren_expr() { |
287 | check_assist( | 290 | check_assist( |
288 | inline_local_varialbe, | 291 | inline_local_variable, |
289 | " | 292 | " |
290 | fn foo() { | 293 | fn foo() { |
291 | let a<|> = ( 10 + 1 ); | 294 | let a<|> = ( 10 + 1 ); |
@@ -317,7 +320,7 @@ fn foo() { | |||
317 | #[test] | 320 | #[test] |
318 | fn test_not_inline_mut_variable() { | 321 | fn test_not_inline_mut_variable() { |
319 | check_assist_not_applicable( | 322 | check_assist_not_applicable( |
320 | inline_local_varialbe, | 323 | inline_local_variable, |
321 | " | 324 | " |
322 | fn foo() { | 325 | fn foo() { |
323 | let mut a<|> = 1 + 1; | 326 | let mut a<|> = 1 + 1; |
@@ -329,7 +332,7 @@ fn foo() { | |||
329 | #[test] | 332 | #[test] |
330 | fn test_call_expr() { | 333 | fn test_call_expr() { |
331 | check_assist( | 334 | check_assist( |
332 | inline_local_varialbe, | 335 | inline_local_variable, |
333 | " | 336 | " |
334 | fn foo() { | 337 | fn foo() { |
335 | let a<|> = bar(10 + 1); | 338 | let a<|> = bar(10 + 1); |
@@ -347,7 +350,7 @@ fn foo() { | |||
347 | #[test] | 350 | #[test] |
348 | fn test_index_expr() { | 351 | fn test_index_expr() { |
349 | check_assist( | 352 | check_assist( |
350 | inline_local_varialbe, | 353 | inline_local_variable, |
351 | " | 354 | " |
352 | fn foo() { | 355 | fn foo() { |
353 | let x = vec![1, 2, 3]; | 356 | let x = vec![1, 2, 3]; |
@@ -367,7 +370,7 @@ fn foo() { | |||
367 | #[test] | 370 | #[test] |
368 | fn test_method_call_expr() { | 371 | fn test_method_call_expr() { |
369 | check_assist( | 372 | check_assist( |
370 | inline_local_varialbe, | 373 | inline_local_variable, |
371 | " | 374 | " |
372 | fn foo() { | 375 | fn foo() { |
373 | let bar = vec![1]; | 376 | let bar = vec![1]; |
@@ -387,7 +390,7 @@ fn foo() { | |||
387 | #[test] | 390 | #[test] |
388 | fn test_field_expr() { | 391 | fn test_field_expr() { |
389 | check_assist( | 392 | check_assist( |
390 | inline_local_varialbe, | 393 | inline_local_variable, |
391 | " | 394 | " |
392 | struct Bar { | 395 | struct Bar { |
393 | foo: usize | 396 | foo: usize |
@@ -415,7 +418,7 @@ fn foo() { | |||
415 | #[test] | 418 | #[test] |
416 | fn test_try_expr() { | 419 | fn test_try_expr() { |
417 | check_assist( | 420 | check_assist( |
418 | inline_local_varialbe, | 421 | inline_local_variable, |
419 | " | 422 | " |
420 | fn foo() -> Option<usize> { | 423 | fn foo() -> Option<usize> { |
421 | let bar = Some(1); | 424 | let bar = Some(1); |
@@ -437,7 +440,7 @@ fn foo() -> Option<usize> { | |||
437 | #[test] | 440 | #[test] |
438 | fn test_ref_expr() { | 441 | fn test_ref_expr() { |
439 | check_assist( | 442 | check_assist( |
440 | inline_local_varialbe, | 443 | inline_local_variable, |
441 | " | 444 | " |
442 | fn foo() { | 445 | fn foo() { |
443 | let bar = 10; | 446 | let bar = 10; |
@@ -455,7 +458,7 @@ fn foo() { | |||
455 | #[test] | 458 | #[test] |
456 | fn test_tuple_expr() { | 459 | fn test_tuple_expr() { |
457 | check_assist( | 460 | check_assist( |
458 | inline_local_varialbe, | 461 | inline_local_variable, |
459 | " | 462 | " |
460 | fn foo() { | 463 | fn foo() { |
461 | let a<|> = (10, 20); | 464 | let a<|> = (10, 20); |
@@ -471,7 +474,7 @@ fn foo() { | |||
471 | #[test] | 474 | #[test] |
472 | fn test_array_expr() { | 475 | fn test_array_expr() { |
473 | check_assist( | 476 | check_assist( |
474 | inline_local_varialbe, | 477 | inline_local_variable, |
475 | " | 478 | " |
476 | fn foo() { | 479 | fn foo() { |
477 | let a<|> = [1, 2, 3]; | 480 | let a<|> = [1, 2, 3]; |
@@ -487,7 +490,7 @@ fn foo() { | |||
487 | #[test] | 490 | #[test] |
488 | fn test_paren() { | 491 | fn test_paren() { |
489 | check_assist( | 492 | check_assist( |
490 | inline_local_varialbe, | 493 | inline_local_variable, |
491 | " | 494 | " |
492 | fn foo() { | 495 | fn foo() { |
493 | let a<|> = (10 + 20); | 496 | let a<|> = (10 + 20); |
@@ -505,7 +508,7 @@ fn foo() { | |||
505 | #[test] | 508 | #[test] |
506 | fn test_path_expr() { | 509 | fn test_path_expr() { |
507 | check_assist( | 510 | check_assist( |
508 | inline_local_varialbe, | 511 | inline_local_variable, |
509 | " | 512 | " |
510 | fn foo() { | 513 | fn foo() { |
511 | let d = 10; | 514 | let d = 10; |
@@ -525,7 +528,7 @@ fn foo() { | |||
525 | #[test] | 528 | #[test] |
526 | fn test_block_expr() { | 529 | fn test_block_expr() { |
527 | check_assist( | 530 | check_assist( |
528 | inline_local_varialbe, | 531 | inline_local_variable, |
529 | " | 532 | " |
530 | fn foo() { | 533 | fn foo() { |
531 | let a<|> = { 10 }; | 534 | let a<|> = { 10 }; |
@@ -543,7 +546,7 @@ fn foo() { | |||
543 | #[test] | 546 | #[test] |
544 | fn test_used_in_different_expr1() { | 547 | fn test_used_in_different_expr1() { |
545 | check_assist( | 548 | check_assist( |
546 | inline_local_varialbe, | 549 | inline_local_variable, |
547 | " | 550 | " |
548 | fn foo() { | 551 | fn foo() { |
549 | let a<|> = 10 + 20; | 552 | let a<|> = 10 + 20; |
@@ -565,7 +568,7 @@ fn foo() { | |||
565 | #[test] | 568 | #[test] |
566 | fn test_used_in_for_expr() { | 569 | fn test_used_in_for_expr() { |
567 | check_assist( | 570 | check_assist( |
568 | inline_local_varialbe, | 571 | inline_local_variable, |
569 | " | 572 | " |
570 | fn foo() { | 573 | fn foo() { |
571 | let a<|> = vec![10, 20]; | 574 | let a<|> = vec![10, 20]; |
@@ -581,7 +584,7 @@ fn foo() { | |||
581 | #[test] | 584 | #[test] |
582 | fn test_used_in_while_expr() { | 585 | fn test_used_in_while_expr() { |
583 | check_assist( | 586 | check_assist( |
584 | inline_local_varialbe, | 587 | inline_local_variable, |
585 | " | 588 | " |
586 | fn foo() { | 589 | fn foo() { |
587 | let a<|> = 1 > 0; | 590 | let a<|> = 1 > 0; |
@@ -597,7 +600,7 @@ fn foo() { | |||
597 | #[test] | 600 | #[test] |
598 | fn test_used_in_break_expr() { | 601 | fn test_used_in_break_expr() { |
599 | check_assist( | 602 | check_assist( |
600 | inline_local_varialbe, | 603 | inline_local_variable, |
601 | " | 604 | " |
602 | fn foo() { | 605 | fn foo() { |
603 | let a<|> = 1 + 1; | 606 | let a<|> = 1 + 1; |
@@ -617,7 +620,7 @@ fn foo() { | |||
617 | #[test] | 620 | #[test] |
618 | fn test_used_in_return_expr() { | 621 | fn test_used_in_return_expr() { |
619 | check_assist( | 622 | check_assist( |
620 | inline_local_varialbe, | 623 | inline_local_variable, |
621 | " | 624 | " |
622 | fn foo() { | 625 | fn foo() { |
623 | let a<|> = 1 > 0; | 626 | let a<|> = 1 > 0; |
@@ -633,7 +636,7 @@ fn foo() { | |||
633 | #[test] | 636 | #[test] |
634 | fn test_used_in_match_expr() { | 637 | fn test_used_in_match_expr() { |
635 | check_assist( | 638 | check_assist( |
636 | inline_local_varialbe, | 639 | inline_local_variable, |
637 | " | 640 | " |
638 | fn foo() { | 641 | fn foo() { |
639 | let a<|> = 1 > 0; | 642 | let a<|> = 1 > 0; |
@@ -645,4 +648,16 @@ fn foo() { | |||
645 | }", | 648 | }", |
646 | ); | 649 | ); |
647 | } | 650 | } |
651 | |||
652 | #[test] | ||
653 | fn test_not_applicable_if_variable_unused() { | ||
654 | check_assist_not_applicable( | ||
655 | inline_local_variable, | ||
656 | " | ||
657 | fn foo() { | ||
658 | let <|>a = 0; | ||
659 | } | ||
660 | ", | ||
661 | ) | ||
662 | } | ||
648 | } | 663 | } |