diff options
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r-- | crates/ide_completion/src/completions/lifetime.rs | 29 | ||||
-rw-r--r-- | crates/ide_completion/src/context.rs | 24 |
2 files changed, 40 insertions, 13 deletions
diff --git a/crates/ide_completion/src/completions/lifetime.rs b/crates/ide_completion/src/completions/lifetime.rs index 07be28e9c..628c1fb9b 100644 --- a/crates/ide_completion/src/completions/lifetime.rs +++ b/crates/ide_completion/src/completions/lifetime.rs | |||
@@ -253,4 +253,33 @@ fn foo() { | |||
253 | "#]], | 253 | "#]], |
254 | ); | 254 | ); |
255 | } | 255 | } |
256 | |||
257 | #[test] | ||
258 | fn complete_label_in_while_cond() { | ||
259 | check( | ||
260 | r#" | ||
261 | fn foo() { | ||
262 | 'outer: while { 'inner: loop { break '$0 } } {} | ||
263 | } | ||
264 | "#, | ||
265 | expect![[r#" | ||
266 | lb 'inner | ||
267 | lb 'outer | ||
268 | "#]], | ||
269 | ); | ||
270 | } | ||
271 | |||
272 | #[test] | ||
273 | fn complete_label_in_for_iterable() { | ||
274 | check( | ||
275 | r#" | ||
276 | fn foo() { | ||
277 | 'outer: for _ in [{ 'inner: loop { break '$0 } }] {} | ||
278 | } | ||
279 | "#, | ||
280 | expect![[r#" | ||
281 | lb 'inner | ||
282 | "#]], | ||
283 | ); | ||
284 | } | ||
256 | } | 285 | } |
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 6cb7e5264..67e2d6f6c 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs | |||
@@ -475,19 +475,17 @@ impl<'a> CompletionContext<'a> { | |||
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | 477 | ||
478 | if parent.kind() != syntax::SyntaxKind::LABEL { | 478 | match_ast! { |
479 | match_ast! { | 479 | match parent { |
480 | match parent { | 480 | ast::LifetimeParam(_it) => { |
481 | ast::LifetimeParam(_it) => { | 481 | self.lifetime_allowed = true; |
482 | self.lifetime_allowed = true; | 482 | self.lifetime_param_syntax = |
483 | self.lifetime_param_syntax = | 483 | self.sema.find_node_at_offset_with_macros(original_file, offset); |
484 | self.sema.find_node_at_offset_with_macros(original_file, offset); | 484 | }, |
485 | }, | 485 | ast::BreakExpr(_it) => self.is_label_ref = true, |
486 | ast::BreakExpr(_it) => self.is_label_ref = true, | 486 | ast::ContinueExpr(_it) => self.is_label_ref = true, |
487 | ast::ContinueExpr(_it) => self.is_label_ref = true, | 487 | ast::Label(_it) => (), |
488 | ast::Label(_it) => (), | 488 | _ => self.lifetime_allowed = true, |
489 | _ => self.lifetime_allowed = true, | ||
490 | } | ||
491 | } | 489 | } |
492 | } | 490 | } |
493 | } | 491 | } |