[CodeComplete] Avoid let/var completions in a few cases

Don't suggest `let` or `var` in e.g the sequence
expression of a `for` loop, or after a `return`.
We ought to do a better job of checking whether
we're in expression position before suggesting
these (as opposed to a pattern), but I'm leaving
that as future work for now.
This commit is contained in:
Hamish Knight
2023-08-03 14:17:54 +01:00
parent c2fc7ee9e7
commit a5d9b13ef0
2 changed files with 24 additions and 10 deletions

View File

@@ -1016,13 +1016,19 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
addStmtKeywords(Sink, CurDeclContext, MaybeFuncBody);
addClosureSignatureKeywordsIfApplicable(Sink, CurDeclContext);
LLVM_FALLTHROUGH;
case CompletionKind::PostfixExprBeginning:
// We need to add 'let' and 'var' keywords in expression position here as
// we initially parse patterns as expressions.
// FIXME: We ought to be able to determine if we're in a pattern context and
// only enable 'let' and 'var' in that case.
addLetVarKeywords(Sink);
LLVM_FALLTHROUGH;
case CompletionKind::ReturnStmtExpr:
case CompletionKind::YieldStmtExpr:
case CompletionKind::PostfixExprBeginning:
case CompletionKind::ForEachSequence:
addSuperKeyword(Sink, CurDeclContext);
addLetVarKeywords(Sink);
addExprKeywords(Sink, CurDeclContext);
addAnyTypeKeyword(Sink, CurDeclContext->getASTContext().TheAnyType);
break;