Skip to content

Commit 15f2b00

Browse files
authored
Merge pull request #23490 from rintaro/ide-completion-emptycall-rdar46215262
[CodeCompletion] Provide empty call pattern after paren
2 parents 232e4a4 + 7ae18ff commit 15f2b00

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,8 +1190,6 @@ void CodeCompletionString::getName(raw_ostream &OS) const {
11901190
}
11911191
}
11921192
}
1193-
assert((TextSize > 0) &&
1194-
"code completion string should have non-empty name!");
11951193
}
11961194

11971195
void CodeCompletionContext::sortCompletionResults(
@@ -2255,14 +2253,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22552253
else
22562254
Builder.addAnnotatedLeftParen();
22572255

2258-
bool anyParam = addCallArgumentPatterns(Builder, AFT->getParams(),
2259-
declParams, includeDefaultArgs);
2260-
2261-
if (HaveLParen && !anyParam) {
2262-
// Empty result, don't add it.
2263-
Builder.cancel();
2264-
return;
2265-
}
2256+
addCallArgumentPatterns(Builder, AFT->getParams(), declParams,
2257+
includeDefaultArgs);
22662258

22672259
// The rparen matches the lparen here so that we insert both or neither.
22682260
if (!HaveLParen)
@@ -2508,14 +2500,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25082500
else
25092501
Builder.addAnnotatedLeftParen();
25102502

2511-
bool anyParam = addCallArgumentPatterns(
2512-
Builder, ConstructorType, CD->getParameters(), includeDefaultArgs);
2513-
2514-
if (HaveLParen && !anyParam) {
2515-
// Empty result, don't add it.
2516-
Builder.cancel();
2517-
return;
2518-
}
2503+
addCallArgumentPatterns(Builder, ConstructorType, CD->getParameters(),
2504+
includeDefaultArgs);
25192505

25202506
// The rparen matches the lparen here so that we insert both or neither.
25212507
if (!HaveLParen)

test/IDE/complete_after_super.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ class SuperDerivedA : SuperBaseA {
262262
}
263263
init (b: Float) {
264264
super.init(#^CONSTRUCTOR_SUPER_INIT_PAREN_1^#
265-
// CONSTRUCTOR_SUPER_INIT_PAREN_1-NOT: Pattern/
265+
// CONSTRUCTOR_SUPER_INIT_PAREN_1: Begin completions, 1 items
266+
// CONSTRUCTOR_SUPER_INIT_PAREN_1: Pattern/CurrModule: ['('][')'][#SuperBaseA#]; name=
267+
// CONSTRUCTOR_SUPER_INIT_PAREN_1: End completions
266268
}
267269

268270
deinit {

test/IDE/complete_call_arg.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,9 @@ _ = EmptyOverload(foo: #^EMPTY_OVERLOAD_2^#)
483483
public func fopen() -> TestBoundGeneric1! { fatalError() }
484484
func other() {
485485
_ = fopen(#^CALLARG_IUO^#)
486-
// CALLARG_IUO-NOT: Begin completions
487-
// CALLARG_IUO-NOT: End completions
486+
// CALLARG_IUO: Begin completions, 1 items
487+
// CALLARG_IUO: Pattern/CurrModule: ['('][')'][#TestBoundGeneric1!#]; name=
488+
// CALLARG_IUO: End completions
488489
}
489490

490491
class Foo { let x: Int }

test/IDE/complete_constructor.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ func testImplicitConstructors1() {
6969
}
7070
func testImplicitConstructors1P() {
7171
ImplicitConstructors1(#^IMPLICIT_CONSTRUCTORS_1P^#
72-
// IMPLICIT_CONSTRUCTORS_1P-NOT: Begin completions
72+
// IMPLICIT_CONSTRUCTORS_1P: Begin completions, 1 items
73+
// IMPLICIT_CONSTRUCTORS_1P: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors1#]; name=
74+
// IMPLICIT_CONSTRUCTORS_1P: End completions
7375
}
7476

7577
struct ImplicitConstructors2 {
@@ -89,6 +91,7 @@ func testImplicitConstructors2P() {
8991
ImplicitConstructors2(#^IMPLICIT_CONSTRUCTORS_2P^#
9092
// IMPLICIT_CONSTRUCTORS_2P: Begin completions
9193
// IMPLICIT_CONSTRUCTORS_2P-NEXT: Decl[Constructor]/CurrNominal: ['(']{#instanceVar: Int#}[')'][#ImplicitConstructors2#]{{; name=.+$}}
94+
// IMPLICIT_CONSTRUCTORS_2P-NEXT: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
9295
// IMPLICIT_CONSTRUCTORS_2P-NEXT: End completions
9396
}
9497

@@ -111,6 +114,7 @@ func testExplicitConstructors1() {
111114
func testExplicitConstructors1P() {
112115
ExplicitConstructors1(#^EXPLICIT_CONSTRUCTORS_1P^#
113116
// EXPLICIT_CONSTRUCTORS_1P: Begin completions
117+
// EXPLICIT_CONSTRUCTORS_1P-NEXT: Decl[Constructor]/CurrNominal: ['('][')'][#ExplicitConstructors1#]; name=
114118
// EXPLICIT_CONSTRUCTORS_1P-NEXT: Decl[Constructor]/CurrNominal: ['(']{#a: Int#}[')'][#ExplicitConstructors1#]{{; name=.+$}}
115119
// EXPLICIT_CONSTRUCTORS_1P-NEXT: Decl[Constructor]/CurrNominal: ['(']{#a: Int#}, {#b: Float#}[')'][#ExplicitConstructors1#]{{; name=.+$}}
116120
// EXPLICIT_CONSTRUCTORS_1P-NEXT: End completions
@@ -276,13 +280,16 @@ struct ExplicitConstructorsDerived3 {
276280

277281
func testHaveRParen1() {
278282
ImplicitConstructors1(#^HAVE_RPAREN_1^#)
279-
// HAVE_RPAREN_1-NOT: Decl[Constructor]
283+
// HAVE_RPAREN_1: Begin completions, 1 items
284+
// HAVE_RPAREN_1: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors1#]; name=
285+
// HAVE_RPAREN_1: End completions
280286
}
281287

282288
func testHaveRParen2() {
283289
ImplicitConstructors2(#^HAVE_RPAREN_2^#)
284290
// HAVE_RPAREN_2-NOT: Decl[Constructor]
285291
// HAVE_RPAREN_2: Decl[Constructor]/CurrNominal: ['(']{#instanceVar: Int#}[')'][#ImplicitConstructors2#]{{; name=.+$}}
292+
// HAVE_RPAREN_2: Decl[Constructor]/CurrNominal: ['('][')'][#ImplicitConstructors2#]; name=
286293
// HAVE_RPAREN_2-NOT: Decl[Constructor]
287294
}
288295

test/IDE/complete_value_expr.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,9 @@ func testInsideFunctionCall0() {
734734
func testInsideFunctionCall1() {
735735
var a = FooStruct()
736736
a.instanceFunc0(#^INSIDE_FUNCTION_CALL_1^#
737-
// There should be no results here because the function call
738-
// unambiguously resolves to overload that takes 0 arguments.
739-
// INSIDE_FUNCTION_CALL_1-NOT: Begin completions
737+
// INSIDE_FUNCTION_CALL_1: Begin completions, 1 items
738+
// INSIDE_FUNCTION_CALL_1: Pattern/CurrModule: ['('][')'][#Void#]; name=
739+
// INSIDE_FUNCTION_CALL_1: End completions
740740
}
741741

742742
func testInsideFunctionCall2() {
@@ -787,8 +787,9 @@ func testInsideFunctionCall7() {
787787

788788
func testInsideFunctionCall8(_ x: inout FooStruct) {
789789
x.instanceFunc0(#^INSIDE_FUNCTION_CALL_8^#)
790-
// Since we already have '()', there is no pattern to complete.
791-
// INSIDE_FUNCTION_CALL_8-NOT: Pattern/{{.*}}:
790+
// INSIDE_FUNCTION_CALL_8: Begin completions
791+
// INSIDE_FUNCTION_CALL_8: Pattern/CurrModule: ['('][')'][#Void#]; name=
792+
// INSIDE_FUNCTION_CALL_8: End completions
792793
}
793794
func testInsideFunctionCall9(_ x: inout FooStruct) {
794795
x.instanceFunc1(#^INSIDE_FUNCTION_CALL_9^#)

0 commit comments

Comments
 (0)