From 030cb5502ec3fe7ff5ba71fb56ee21a104664859 Mon Sep 17 00:00:00 2001 From: Tim van Elsloo Date: Sun, 15 Jan 2023 22:14:22 +0100 Subject: [PATCH] Improved completion for variable definitions. --- litho-lsp/src/completion.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/litho-lsp/src/completion.rs b/litho-lsp/src/completion.rs index 6d823ed..e295d13 100644 --- a/litho-lsp/src/completion.rs +++ b/litho-lsp/src/completion.rs @@ -189,18 +189,6 @@ impl<'a> CompletionVisitor<'a> { let name = match ty { Type::List(_) => { - // items.push(CompletionItem { - // label: "[".to_owned(), - // label_details: Some(CompletionItemLabelDetails { - // detail: Some("...]".to_owned()), - // description: None, - // }), - // insert_text: Some("[${0}]".to_owned()), - // insert_text_format: Some(InsertTextFormat::SNIPPET), - // kind: Some(CompletionItemKind::OPERATOR), - // ..Default::default() - // }); - return items.into_iter(); } ty => match ty.name() { @@ -460,4 +448,22 @@ impl<'a> Visit<'a, SmolStr> for CompletionVisitor<'a> { _ => {} } } + + fn visit_variable_definitions( + &self, + node: &'a VariableDefinitions, + accumulator: &mut Self::Accumulator, + ) { + if !node.parens.span().contains(self.offset) { + return; + } + + for definition in node.variable_definitions.iter() { + if !definition.colon.span().before(self.offset) { + continue; + } + + accumulator.extend(self.complete_all_types(true)); + } + } }