From 64957acb5f359763395a54e314d1f5d5cfc6ccf3 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 21 Mar 2021 01:10:59 +0100 Subject: Fix incorrect scoping in while expressions --- crates/ide_completion/src/completions/lifetime.rs | 29 +++++++++++++++++++++++ crates/ide_completion/src/context.rs | 24 +++++++++---------- 2 files changed, 40 insertions(+), 13 deletions(-) (limited to 'crates/ide_completion') 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() { "#]], ); } + + #[test] + fn complete_label_in_while_cond() { + check( + r#" +fn foo() { + 'outer: while { 'inner: loop { break '$0 } } {} +} +"#, + expect![[r#" + lb 'inner + lb 'outer + "#]], + ); + } + + #[test] + fn complete_label_in_for_iterable() { + check( + r#" +fn foo() { + 'outer: for _ in [{ 'inner: loop { break '$0 } }] {} +} +"#, + expect![[r#" + lb 'inner + "#]], + ); + } } 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> { return; } - if parent.kind() != syntax::SyntaxKind::LABEL { - match_ast! { - match parent { - ast::LifetimeParam(_it) => { - self.lifetime_allowed = true; - self.lifetime_param_syntax = - self.sema.find_node_at_offset_with_macros(original_file, offset); - }, - ast::BreakExpr(_it) => self.is_label_ref = true, - ast::ContinueExpr(_it) => self.is_label_ref = true, - ast::Label(_it) => (), - _ => self.lifetime_allowed = true, - } + match_ast! { + match parent { + ast::LifetimeParam(_it) => { + self.lifetime_allowed = true; + self.lifetime_param_syntax = + self.sema.find_node_at_offset_with_macros(original_file, offset); + }, + ast::BreakExpr(_it) => self.is_label_ref = true, + ast::ContinueExpr(_it) => self.is_label_ref = true, + ast::Label(_it) => (), + _ => self.lifetime_allowed = true, } } } -- cgit v1.2.3