diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-21 00:29:15 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-21 00:29:15 +0000 |
commit | a0ed87ff56e83eb03910b58a9cb80c35c5639338 (patch) | |
tree | 9360702f2aaf0c4672a9ed74c51604a8353662a0 /crates/ide_completion/src/context.rs | |
parent | 787bd3c5516d250245f6070308d689311b638fbe (diff) | |
parent | 64957acb5f359763395a54e314d1f5d5cfc6ccf3 (diff) |
Merge #8127
8127: Add label completion r=Veykril a=Veykril
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/context.rs')
-rw-r--r-- | crates/ide_completion/src/context.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 4c2b31084..67e2d6f6c 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs | |||
@@ -53,6 +53,7 @@ pub(crate) struct CompletionContext<'a> { | |||
53 | /// FIXME: `ActiveParameter` is string-based, which is very very wrong | 53 | /// FIXME: `ActiveParameter` is string-based, which is very very wrong |
54 | pub(super) active_parameter: Option<ActiveParameter>, | 54 | pub(super) active_parameter: Option<ActiveParameter>, |
55 | pub(super) is_param: bool, | 55 | pub(super) is_param: bool, |
56 | pub(super) is_label_ref: bool, | ||
56 | /// If a name-binding or reference to a const in a pattern. | 57 | /// If a name-binding or reference to a const in a pattern. |
57 | /// Irrefutable patterns (like let) are excluded. | 58 | /// Irrefutable patterns (like let) are excluded. |
58 | pub(super) is_pat_binding_or_const: bool, | 59 | pub(super) is_pat_binding_or_const: bool, |
@@ -155,6 +156,7 @@ impl<'a> CompletionContext<'a> { | |||
155 | record_field_syntax: None, | 156 | record_field_syntax: None, |
156 | impl_def: None, | 157 | impl_def: None, |
157 | active_parameter: ActiveParameter::at(db, position), | 158 | active_parameter: ActiveParameter::at(db, position), |
159 | is_label_ref: false, | ||
158 | is_param: false, | 160 | is_param: false, |
159 | is_pat_binding_or_const: false, | 161 | is_pat_binding_or_const: false, |
160 | is_irrefutable_pat_binding: false, | 162 | is_irrefutable_pat_binding: false, |
@@ -468,12 +470,24 @@ impl<'a> CompletionContext<'a> { | |||
468 | ) { | 470 | ) { |
469 | self.lifetime_syntax = | 471 | self.lifetime_syntax = |
470 | find_node_at_offset(original_file, lifetime.syntax().text_range().start()); | 472 | find_node_at_offset(original_file, lifetime.syntax().text_range().start()); |
471 | if lifetime.syntax().parent().map_or(false, |p| p.kind() != syntax::SyntaxKind::ERROR) { | 473 | if let Some(parent) = lifetime.syntax().parent() { |
472 | self.lifetime_allowed = true; | 474 | if parent.kind() == syntax::SyntaxKind::ERROR { |
473 | } | 475 | return; |
474 | if let Some(_) = lifetime.syntax().parent().and_then(ast::LifetimeParam::cast) { | 476 | } |
475 | self.lifetime_param_syntax = | 477 | |
476 | self.sema.find_node_at_offset_with_macros(original_file, offset); | 478 | match_ast! { |
479 | match parent { | ||
480 | ast::LifetimeParam(_it) => { | ||
481 | self.lifetime_allowed = true; | ||
482 | self.lifetime_param_syntax = | ||
483 | self.sema.find_node_at_offset_with_macros(original_file, offset); | ||
484 | }, | ||
485 | ast::BreakExpr(_it) => self.is_label_ref = true, | ||
486 | ast::ContinueExpr(_it) => self.is_label_ref = true, | ||
487 | ast::Label(_it) => (), | ||
488 | _ => self.lifetime_allowed = true, | ||
489 | } | ||
490 | } | ||
477 | } | 491 | } |
478 | } | 492 | } |
479 | 493 | ||