Skip to content

Commit 1380650

Browse files
committed
[CodeCompletion] Provide empty call pattern after paren
This improves discoverability of no-parameter initializers. rdar://problem/46215262 (cherry picked from commit 7ae18ff)
1 parent 61bf3e2 commit 1380650

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
@@ -1185,8 +1185,6 @@ void CodeCompletionString::getName(raw_ostream &OS) const {
11851185
}
11861186
}
11871187
}
1188-
assert((TextSize > 0) &&
1189-
"code completion string should have non-empty name!");
11901188
}
11911189

11921190
void CodeCompletionContext::sortCompletionResults(
@@ -2249,14 +2247,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22492247
else
22502248
Builder.addAnnotatedLeftParen();
22512249

2252-
bool anyParam = addCallArgumentPatterns(Builder, AFT->getParams(),
2253-
declParams, includeDefaultArgs);
2254-
2255-
if (HaveLParen && !anyParam) {
2256-
// Empty result, don't add it.
2257-
Builder.cancel();
2258-
return;
2259-
}
2250+
addCallArgumentPatterns(Builder, AFT->getParams(), declParams,
2251+
includeDefaultArgs);
22602252

22612253
// The rparen matches the lparen here so that we insert both or neither.
22622254
if (!HaveLParen)
@@ -2502,14 +2494,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
25022494
else
25032495
Builder.addAnnotatedLeftParen();
25042496

2505-
bool anyParam = addCallArgumentPatterns(
2506-
Builder, ConstructorType, CD->getParameters(), includeDefaultArgs);
2507-
2508-
if (HaveLParen && !anyParam) {
2509-
// Empty result, don't add it.
2510-
Builder.cancel();
2511-
return;
2512-
}
2497+
addCallArgumentPatterns(Builder, ConstructorType, CD->getParameters(),
2498+
includeDefaultArgs);
25132499

25142500
// The rparen matches the lparen here so that we insert both or neither.
25152501
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)