Skip to content

Commit a8fa551

Browse files
authored
Merge pull request #37477 from hamishknight/an-effectful-argument
[CodeComplete] Include expr keywords in argument completion
2 parents e7e3097 + 010bcc1 commit a8fa551

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5961,7 +5961,6 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
59615961
case CompletionKind::PoundAvailablePlatform:
59625962
case CompletionKind::Import:
59635963
case CompletionKind::UnresolvedMember:
5964-
case CompletionKind::CallArg:
59655964
case CompletionKind::LabeledTrailingClosure:
59665965
case CompletionKind::AfterPoundExpr:
59675966
case CompletionKind::AfterPoundDirective:
@@ -6014,12 +6013,19 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
60146013
addAnyTypeKeyword(Sink, CurDeclContext->getASTContext().TheAnyType);
60156014
break;
60166015

6016+
case CompletionKind::CallArg:
6017+
case CompletionKind::PostfixExprParen:
6018+
// Note that we don't add keywords here as the completion might be for
6019+
// an argument list pattern. We instead add keywords later in
6020+
// CodeCompletionCallbacksImpl::doneParsing when we know we're not
6021+
// completing for a argument list pattern.
6022+
break;
6023+
60176024
case CompletionKind::CaseStmtKeyword:
60186025
addCaseStmtKeywords(Sink);
60196026
break;
60206027

60216028
case CompletionKind::PostfixExpr:
6022-
case CompletionKind::PostfixExprParen:
60236029
case CompletionKind::CaseStmtBeginning:
60246030
case CompletionKind::TypeIdentifierWithDot:
60256031
case CompletionKind::TypeIdentifierWithoutDot:
@@ -6657,6 +6663,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
66576663
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
66586664
ContextInfo.isImplicitSingleExpressionReturn());
66596665
Lookup.setHaveLParen(false);
6666+
6667+
// Add any keywords that can be used in an argument expr position.
6668+
addSuperKeyword(CompletionContext.getResultSink());
6669+
addExprKeywords(CompletionContext.getResultSink());
6670+
66606671
DoPostfixExprBeginning();
66616672
}
66626673
break;
@@ -6798,6 +6809,11 @@ void CodeCompletionCallbacksImpl::doneParsing() {
67986809
if (shouldPerformGlobalCompletion) {
67996810
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
68006811
ContextInfo.isImplicitSingleExpressionReturn());
6812+
6813+
// Add any keywords that can be used in an argument expr position.
6814+
addSuperKeyword(CompletionContext.getResultSink());
6815+
addExprKeywords(CompletionContext.getResultSink());
6816+
68016817
DoPostfixExprBeginning();
68026818
}
68036819
break;

test/IDE/complete_call_arg.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class C1 {
9898
// EXPECT_OINT-DAG: Decl[GlobalVar]/CurrModule/TypeRelation[Identical]: oi2[#Int?#]; name=oi2
9999
// EXPECT_OINT-DAG: Decl[GlobalVar]/CurrModule/TypeRelation[Identical]: oi1[#Int?#]; name=oi1
100100
// EXPECT_OINT-DAG: Decl[GlobalVar]/CurrModule: os1[#String?#]; name=os1
101+
// EXPECT_OINT-DAG: Keyword[try]/None: try; name=try
102+
// EXPECT_OINT-DAG: Keyword[try]/None: try!; name=try!
103+
// EXPECT_OINT-DAG: Keyword[try]/None: try?; name=try?
104+
// EXPECT_OINT-DAG: Keyword/None: await; name=await
105+
// EXPECT_OINT-NOT: Keyword[super]
101106
// EXPECT_OINT: End completions
102107

103108
// EXPECT_INT: Begin completions
@@ -112,6 +117,11 @@ class C1 {
112117
// EXPECT_INT-DAG: Decl[GlobalVar]/CurrModule: oi1[#Int?#]; name=oi1
113118
// EXPECT_INT-DAG: Decl[GlobalVar]/CurrModule: os2[#String?#]; name=os2
114119
// EXPECT_INT-DAG: Decl[GlobalVar]/CurrModule: oi2[#Int?#]; name=oi2
120+
// EXPECT_INT-DAG: Keyword[try]/None: try; name=try
121+
// EXPECT_INT-DAG: Keyword[try]/None: try!; name=try!
122+
// EXPECT_INT-DAG: Keyword[try]/None: try?; name=try?
123+
// EXPECT_INT-DAG: Keyword/None: await; name=await
124+
// EXPECT_INT-NOT: Keyword[super]
115125
// EXPECT_INT: End completions
116126

117127
class C2 {
@@ -140,6 +150,11 @@ class C2 {
140150
// EXPECT_OSTRING-DAG: Decl[FreeFunction]/CurrModule/TypeRelation[Identical]: ostringGen()[#String?#]; name=ostringGen()
141151
// EXPECT_OSTRING-DAG: Decl[GlobalVar]/CurrModule: i1[#Int#]; name=i1
142152
// EXPECT_OSTRING-DAG: Decl[GlobalVar]/CurrModule: i2[#Int#]; name=i2
153+
// EXPECT_OSTRING-DAG: Keyword[try]/None: try; name=try
154+
// EXPECT_OSTRING-DAG: Keyword[try]/None: try!; name=try!
155+
// EXPECT_OSTRING-DAG: Keyword[try]/None: try?; name=try?
156+
// EXPECT_OSTRING-DAG: Keyword/None: await; name=await
157+
// EXPECT_OSTRING-NOT: Keyword[super]
143158
// EXPECT_OSTRING: End completions
144159

145160
// EXPECT_STRING: Begin completions
@@ -151,6 +166,11 @@ class C2 {
151166
// EXPECT_STRING-DAG: Decl[GlobalVar]/CurrModule/TypeRelation[Identical]: s2[#String#]; name=s2
152167
// EXPECT_STRING-DAG: Decl[GlobalVar]/CurrModule: os1[#String?#]; name=os1
153168
// EXPECT_STRING-DAG: Decl[GlobalVar]/CurrModule: os2[#String?#]; name=os2
169+
// EXPECT_STRING-DAG: Keyword[try]/None: try; name=try
170+
// EXPECT_STRING-DAG: Keyword[try]/None: try!; name=try!
171+
// EXPECT_STRING-DAG: Keyword[try]/None: try?; name=try?
172+
// EXPECT_STRING-DAG: Keyword/None: await; name=await
173+
// EXPECT_STRING-NOT: Keyword[super]
154174
// EXPECT_STRING: End completions
155175

156176
func foo2(_ a : C1, b1 : C2) {}
@@ -318,6 +338,11 @@ class C4 {
318338
// MEMBER1-DAG: Decl[InstanceMethod]/CurrNominal: StringOpGen()[#String?#]; name=StringOpGen()
319339
// MEMBER1-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: IntTaker({#(i1): Int#}, {#i2: Int#})[#Void#]; name=IntTaker(i1: Int, i2: Int)
320340
// MEMBER1-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: StringTaker({#(s1): String#}, {#s2: String#})[#Void#]; name=StringTaker(s1: String, s2: String)
341+
// MEMBER1-NOT: Keyword[try]/None: try; name=try
342+
// MEMBER1-NOT: Keyword[try]/None: try!; name=try!
343+
// MEMBER1-NOT: Keyword[try]/None: try?; name=try?
344+
// MEMBER1-NOT: Keyword/None: await; name=await
345+
// MEMBER1-NOT: Keyword[super]
321346

322347
// MEMBER2: Begin completions
323348
// MEMBER2-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: IntGen()[#Int#]; name=IntGen()
@@ -365,6 +390,16 @@ class C4 {
365390
// FARG6-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: InternalIntTaker({#(i1): Int#}, {#i2: Int#})[#Void#]
366391
// FARG6-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: InternalStringTaker({#(s1): String#}, {#s2: String#})[#Void#]
367392

393+
class C5 {}
394+
class C6 : C5 {
395+
func f1() {
396+
foo(3, b: #^ARGSUPER?check=EXPECT-SUPER^#)
397+
}
398+
}
399+
400+
// EXPECT-SUPER: Begin completions
401+
// EXPECT-SUPER-DAG: Keyword[super]/CurrNominal: super[#C5#]; name=super
402+
368403
func firstArg(arg1 arg1: Int, arg2: Int) {}
369404
func testArg1Name1() {
370405
firstArg(#^FIRST_ARG_NAME_1?check=FIRST_ARG_NAME_PATTERN^#
@@ -485,6 +520,11 @@ func testSubscript(obj: HasSubscript, intValue: Int, strValue: String) {
485520
// SUBSCRIPT_1-DAG: Decl[GlobalVar]/CurrModule/TypeRelation[Identical]: i2[#Int#]; name=i2
486521
// SUBSCRIPT_1-DAG: Decl[GlobalVar]/CurrModule: s1[#String#]; name=s1
487522
// SUBSCRIPT_1-DAG: Decl[GlobalVar]/CurrModule: s2[#String#]; name=s2
523+
// SUBSCRIPT_1-DAG: Keyword[try]/None: try; name=try
524+
// SUBSCRIPT_1-DAG: Keyword[try]/None: try!; name=try!
525+
// SUBSCRIPT_1-DAG: Keyword[try]/None: try?; name=try?
526+
// SUBSCRIPT_1-DAG: Keyword/None: await; name=await
527+
// SUBSCRIPT_1-NOT: Keyword[super]
488528

489529
let _ = obj[.#^SUBSCRIPT_1_DOT^#
490530
// SUBSCRIPT_1_DOT: Begin completions
@@ -509,6 +549,11 @@ func testSubscript(obj: HasSubscript, intValue: Int, strValue: String) {
509549
// SUBSCRIPT_3-DAG: Decl[GlobalVar]/CurrModule: i2[#Int#]; name=i2
510550
// SUBSCRIPT_3-DAG: Decl[GlobalVar]/CurrModule/TypeRelation[Identical]: s1[#String#]; name=s1
511551
// SUBSCRIPT_3-DAG: Decl[GlobalVar]/CurrModule/TypeRelation[Identical]: s2[#String#]; name=s2
552+
// SUBSCRIPT_3-DAG: Keyword[try]/None: try; name=try
553+
// SUBSCRIPT_3-DAG: Keyword[try]/None: try!; name=try!
554+
// SUBSCRIPT_3-DAG: Keyword[try]/None: try?; name=try?
555+
// SUBSCRIPT_3-DAG: Keyword/None: await; name=await
556+
// SUBSCRIPT_3-NOT: Keyword[super]
512557

513558
let _ = obj[42, default: .#^SUBSCRIPT_3_DOT^#
514559
// SUBSCRIPT_3_DOT: Begin completions

0 commit comments

Comments
 (0)