@@ -1669,6 +1669,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
16691669 void completeGenericRequirement () override ;
16701670 void completeAfterIfStmt (bool hasElse) override ;
16711671 void completeStmtLabel (StmtKind ParentKind) override ;
1672+ void completeForEachPatternBeginning (bool hasTry, bool hasAwait) override ;
16721673
16731674 void doneParsing () override ;
16741675
@@ -5820,6 +5821,17 @@ void CodeCompletionCallbacksImpl::completeStmtLabel(StmtKind ParentKind) {
58205821 ParentStmtKind = ParentKind;
58215822}
58225823
5824+ void CodeCompletionCallbacksImpl::completeForEachPatternBeginning (
5825+ bool hasTry, bool hasAwait) {
5826+ CurDeclContext = P.CurDeclContext ;
5827+ Kind = CompletionKind::ForEachPatternBeginning;
5828+ ParsedKeywords.clear ();
5829+ if (hasTry)
5830+ ParsedKeywords.emplace_back (" try" );
5831+ if (hasAwait)
5832+ ParsedKeywords.emplace_back (" await" );
5833+ }
5834+
58235835static bool isDynamicLookup (Type T) {
58245836 return T->getRValueType ()->isAnyObject ();
58255837}
@@ -6055,6 +6067,13 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
60556067 case CompletionKind::AfterIfStmtElse:
60566068 addKeyword (Sink, " if" , CodeCompletionKeywordKind::kw_if);
60576069 break ;
6070+ case CompletionKind::ForEachPatternBeginning:
6071+ if (!llvm::is_contained (ParsedKeywords, " try" ))
6072+ addKeyword (Sink, " try" , CodeCompletionKeywordKind::kw_try);
6073+ if (!llvm::is_contained (ParsedKeywords, " await" ))
6074+ addKeyword (Sink, " await" , CodeCompletionKeywordKind::None);
6075+ addKeyword (Sink, " var" , CodeCompletionKeywordKind::kw_var);
6076+ addKeyword (Sink, " case" , CodeCompletionKeywordKind::kw_case);
60586077 }
60596078}
60606079
@@ -6945,6 +6964,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
69456964 case CompletionKind::AfterIfStmtElse:
69466965 case CompletionKind::CaseStmtKeyword:
69476966 case CompletionKind::EffectsSpecifier:
6967+ case CompletionKind::ForEachPatternBeginning:
69486968 // Handled earlier by keyword completions.
69496969 break ;
69506970 }
0 commit comments