From b184bfad7a2dc6a9bf6654a7eec6c68a27c49f70 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 20 Dec 2020 18:19:23 +0100 Subject: Add completions for patterns --- crates/completion/src/context.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'crates/completion/src/context.rs') diff --git a/crates/completion/src/context.rs b/crates/completion/src/context.rs index 5cd11cf77..41de324d8 100644 --- a/crates/completion/src/context.rs +++ b/crates/completion/src/context.rs @@ -51,7 +51,7 @@ pub(crate) struct CompletionContext<'a> { /// If a name-binding or reference to a const in a pattern. /// Irrefutable patterns (like let) are excluded. pub(super) is_pat_binding_or_const: bool, - pub(super) is_irrefutable_let_pat_binding: bool, + pub(super) is_irrefutable_pat_binding: bool, /// A single-indent path, like `foo`. `::foo` should not be considered a trivial path. pub(super) is_trivial_path: bool, /// If not a trivial path, the prefix (qualifier). @@ -147,7 +147,7 @@ impl<'a> CompletionContext<'a> { active_parameter: ActiveParameter::at(db, position), is_param: false, is_pat_binding_or_const: false, - is_irrefutable_let_pat_binding: false, + is_irrefutable_pat_binding: false, is_trivial_path: false, path_qual: None, after_if: false, @@ -327,14 +327,19 @@ impl<'a> CompletionContext<'a> { if bind_pat.syntax().parent().and_then(ast::RecordPatFieldList::cast).is_some() { self.is_pat_binding_or_const = false; } - if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) { - if let Some(pat) = let_stmt.pat() { - if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range()) - { - self.is_pat_binding_or_const = false; - self.is_irrefutable_let_pat_binding = true; + if let Some(Some(pat)) = bind_pat.syntax().ancestors().find_map(|node| { + match_ast! { + match node { + ast::LetStmt(it) => Some(it.pat()), + ast::Param(it) => Some(it.pat()), + _ => None, } } + }) { + if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range()) { + self.is_pat_binding_or_const = false; + self.is_irrefutable_pat_binding = true; + } } } if is_node::(name.syntax()) { -- cgit v1.2.3