Skip to content

Commit 82eca57

Browse files
committed
[CodeCompletion] Complete 'await' in expression position
rdar://problem/72199267
1 parent f4e74f7 commit 82eca57

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5737,11 +5737,15 @@ static void addObserverKeywords(CodeCompletionResultSink &Sink) {
57375737
addKeyword(Sink, "didSet", CodeCompletionKeywordKind::None);
57385738
}
57395739

5740-
static void addExprKeywords(CodeCompletionResultSink &Sink) {
5740+
static void addExprKeywords(CodeCompletionResultSink &Sink,
5741+
bool IsConcurrencyEnabled) {
57415742
// Expr keywords.
57425743
addKeyword(Sink, "try", CodeCompletionKeywordKind::kw_try);
57435744
addKeyword(Sink, "try!", CodeCompletionKeywordKind::kw_try);
57445745
addKeyword(Sink, "try?", CodeCompletionKeywordKind::kw_try);
5746+
if (IsConcurrencyEnabled) {
5747+
addKeyword(Sink, "await", CodeCompletionKeywordKind::None);
5748+
}
57455749
}
57465750

57475751
static void addOpaqueTypeKeyword(CodeCompletionResultSink &Sink) {
@@ -5808,7 +5812,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
58085812
case CompletionKind::ForEachSequence:
58095813
addSuperKeyword(Sink);
58105814
addLetVarKeywords(Sink);
5811-
addExprKeywords(Sink);
5815+
addExprKeywords(Sink, Context.LangOpts.EnableExperimentalConcurrency);
58125816
addAnyTypeKeyword(Sink, CurDeclContext->getASTContext().TheAnyType);
58135817
break;
58145818

@@ -6635,7 +6639,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
66356639
addStmtKeywords(Sink, MaybeFuncBody);
66366640
addSuperKeyword(Sink);
66376641
addLetVarKeywords(Sink);
6638-
addExprKeywords(Sink);
6642+
addExprKeywords(Sink, Context.LangOpts.EnableExperimentalConcurrency);
66396643
addAnyTypeKeyword(Sink, Context.TheAnyType);
66406644
DoPostfixExprBeginning();
66416645
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -enable-experimental-concurrency
2+
3+
// CHECK_DECL: NOT
4+
5+
#^GLOBAL^#
6+
// GLOBAL: Begin completions
7+
// GLOBAL-DAG: Keyword/None: actor; name=actor
8+
// GLOBAL-DAG: Keyword/None: await; name=await
9+
// GLOBAL: End completion
10+
11+
enum Namespace {
12+
#^TYPEMEMBER^#
13+
// TYPEMEMBER: Begin completions
14+
// TYPEMEMBER-NOT: await
15+
// TYPEMEMBER-DAG: Keyword/None: actor; name=actor
16+
// TYPEMEMBER-NOT: await
17+
// TYPEMEMBER: End completion
18+
}
19+
20+
func testFunc() {
21+
#^STMT^#
22+
// STMT: Begin completions
23+
// STMT-DAG: Keyword/None: actor; name=actor
24+
// STMT-DAG: Keyword/None: await; name=await
25+
// STMT: End completion
26+
}
27+
28+
func testExpr() {
29+
_ = #^EXPR^#
30+
// EXPR: Begin completions
31+
// EXPR-NOT: actor
32+
// EXPR-DAG: Keyword/None: await; name=await
33+
// EXPR-NOT: actor
34+
// EXPR: End completion
35+
}
36+
func testClosure() {
37+
func receiveClosure(_: () async -> Void) {}
38+
receiveClosure { #^IN_CLOSURE?check=STMT^# }
39+
}
40+
41+
func testFunc(x: Int = #^FUNCDEFAULTPARAM?check=EXPR^#) {}
42+
43+
struct Something {
44+
var x = #^MEMBERINIT?check=EXPR^#
45+
func testFunc(x: Int = #^METHODDEFAULTPARAM?check=EXPR^#) {}
46+
}

0 commit comments

Comments
 (0)