Skip to content

Commit 39c0afc

Browse files
committed
[Completion] Addd constructors from the completion cache back
31dee1c refactored the completion filter, accidentally dropping initializers when found from the cache. Add these back in and also modify the existing test to load from the cache as well. Resolves rdar://107807707.
1 parent 5e90d32 commit 39c0afc

File tree

2 files changed

+75
-70
lines changed

2 files changed

+75
-70
lines changed

lib/IDE/CodeCompletionConsumer.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ static MutableArrayRef<CodeCompletionResult *> copyCodeCompletionResults(
3737
return false;
3838

3939
switch (R->getAssociatedDeclKind()) {
40+
case CodeCompletionDeclKind::EnumElement:
41+
case CodeCompletionDeclKind::Constructor:
42+
case CodeCompletionDeclKind::Destructor:
43+
case CodeCompletionDeclKind::Subscript:
44+
case CodeCompletionDeclKind::StaticMethod:
45+
case CodeCompletionDeclKind::InstanceMethod:
4046
case CodeCompletionDeclKind::PrefixOperatorFunction:
4147
case CodeCompletionDeclKind::PostfixOperatorFunction:
4248
case CodeCompletionDeclKind::InfixOperatorFunction:
4349
case CodeCompletionDeclKind::FreeFunction:
50+
case CodeCompletionDeclKind::StaticVar:
51+
case CodeCompletionDeclKind::InstanceVar:
52+
case CodeCompletionDeclKind::LocalVar:
4453
case CodeCompletionDeclKind::GlobalVar:
4554
return filter.contains(CodeCompletionFilterFlag::Expr);
4655

@@ -60,20 +69,9 @@ static MutableArrayRef<CodeCompletionResult *> copyCodeCompletionResults(
6069

6170
case CodeCompletionDeclKind::Macro:
6271
return (bool)(R->getMacroRoles() & expectedMacroRoles);
63-
64-
case CodeCompletionDeclKind::EnumElement:
65-
case CodeCompletionDeclKind::Constructor:
66-
case CodeCompletionDeclKind::Destructor:
67-
case CodeCompletionDeclKind::Subscript:
68-
case CodeCompletionDeclKind::StaticMethod:
69-
case CodeCompletionDeclKind::InstanceMethod:
70-
case CodeCompletionDeclKind::StaticVar:
71-
case CodeCompletionDeclKind::InstanceVar:
72-
case CodeCompletionDeclKind::LocalVar:
73-
break;
7472
}
7573

76-
return false;
74+
llvm_unreachable("Unhandled associated decl kind");
7775
};
7876

7977
USRBasedTypeContext USRTypeContext(TypeContext, source.USRTypeArena);

test/IDE/complete_init.swift

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,97 @@
1-
// RUN: sed -n -e '1,/NO_ERRORS_UP_TO_HERE$/ p' %s > %t_no_errors.swift
2-
// RUN: %target-swift-frontend -typecheck -verify %t_no_errors.swift
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/mods)
3+
// RUN: %empty-directory(%t/co-same)
4+
// RUN: %empty-directory(%t/co-across)
5+
// RUN: split-file %s %t --leading-lines
36

4-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=TOP_LEVEL_0 > %t
5-
// RUN: %FileCheck %s -check-prefix=TOP_LEVEL_0 < %t
6-
// RUN: %FileCheck %s -check-prefix=NEGATIVE_TOP_LEVEL_0 < %t
7+
// Completion in the current file/module
8+
// RUN: %target-swift-ide-test -batch-code-completion -code-complete-inits-in-postfix-expr -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t/co-same
79

8-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=TOP_LEVEL_1 > %t.generic
9-
// RUN: %FileCheck %s -check-prefix=TOP_LEVEL_0 < %t.generic
10-
// RUN: %FileCheck %s -check-prefix=GENERIC_PARAM_0 < %t.generic
11-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=K_QUALIFIED_0 | %FileCheck %s -check-prefix=K_QUALIFIED_0
12-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=L_QUALIFIED_0 | %FileCheck %s -check-prefix=L_QUALIFIED_0
13-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=L_QUALIFIED_0 | %FileCheck %s -check-prefix=NEGATIVE_L_QUALIFIED_0
14-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=INSIDE_L_0 | %FileCheck %s -check-prefix=INSIDE_L_0
15-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-complete-inits-in-postfix-expr -code-completion-token=INSIDE_M_0 | %FileCheck %s -check-prefix=INSIDE_M_0
16-
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=ALIAS_CONSTRUCTOR_0 | %FileCheck %s -check-prefix=ALIAS_CONSTRUCTOR_0
10+
// Completion across modules
11+
// RUN: %target-swift-frontend -emit-module %t/InitTypes.swift -o %t/mods/
12+
// RUN: %target-swift-ide-test -batch-code-completion -code-complete-inits-in-postfix-expr -source-filename %t/InitUses.swift -filecheck %raw-FileCheck -completion-output-dir %t/co-across -I %t/mods -D SEPARATED
1713

18-
struct A {
19-
// implicit init()
14+
//--- InitTypes.swift
15+
public struct A {
16+
public init() {}
2017
}
2118

22-
struct B {
19+
public struct B {
2320
let x: A, y: A, z: A
24-
// implicit init(x:,y:,z:)
21+
public init(x: A, y: A, z: A) {
22+
self.x = x
23+
self.y = y
24+
self.z = z
25+
}
2526
}
2627

27-
struct C {
28-
init() {}
29-
init(x: A) {}
30-
init(y: A=A()) {}
28+
public struct C {
29+
public init() {}
30+
public init(x: A) {}
31+
public init(y: A=A()) {}
3132
}
3233

33-
class D {
34-
// implicit init()
34+
public class D {
35+
public init() {}
3536
}
36-
class E {
37-
init(x: A) {}
37+
public class E {
38+
public init(x: A) {}
3839
}
3940

40-
class F : E {
41+
public class F : E {
4142
// inherited init(x: A)
42-
convenience init() {}
43+
public convenience init() {
44+
self.init(x: A())
45+
}
4346
}
4447

45-
protocol G {
48+
public protocol G {
4649
init(x: A)
4750
}
4851

49-
struct H : G {
50-
init(x: A) {}
52+
public struct H : G {
53+
public init(x: A) {}
5154
}
5255

53-
protocol I : G {
56+
public protocol I : G {
5457
init(y: A)
5558
}
5659

57-
typealias J = A
60+
public typealias J = A
5861

59-
struct K {
60-
typealias X = A
61-
struct Y {}
62+
public struct K {
63+
public typealias X = A
64+
public struct Y {
65+
public init() {}
66+
}
6267
}
6368

64-
struct L<X: G> {
65-
typealias Y = X
69+
public struct L<X: G> {
70+
public typealias Y = X
6671
}
6772

68-
// NO_ERRORS_UP_TO_HERE
69-
73+
//--- InitUses.swift
74+
#if SEPARATED
75+
import InitTypes
76+
#endif
7077

7178
func testTopLevel() {
72-
#^TOP_LEVEL_0^#
73-
}
74-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: A()[#A#]{{; name=.+}}
75-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: B({#x: A#}, {#y: A#}, {#z: A#})[#B#]{{; name=.+}}
76-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: C()[#C#]{{; name=.+}}
77-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: C({#x: A#})[#C#]{{; name=.+}}
78-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: C({#y: A#})[#C#]{{; name=.+}}
79-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: D()[#D#]{{; name=.+}}
80-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: E({#x: A#})[#E#]{{; name=.+}}
81-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: F({#x: A#})[#F#]{{; name=.+}}
82-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: F()[#F#]{{; name=.+}}
83-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: H({#x: A#})[#H#]{{; name=.+}}
84-
// TOP_LEVEL_0-DAG: Decl[Constructor]/CurrModule: J()[#A#]{{; name=.+}}
85-
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/CurrModule: E()
86-
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/CurrModule: G(
87-
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/CurrModule: I(
79+
#^TOP_LEVEL_0?check=TOP_LEVEL_0;check=NEGATIVE_TOP_LEVEL_0^#
80+
}
81+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: A()[#A#]{{; name=.+}}
82+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: B({#x: A#}, {#y: A#}, {#z: A#})[#B#]{{; name=.+}}
83+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: C()[#C#]{{; name=.+}}
84+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: C({#x: A#})[#C#]{{; name=.+}}
85+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: C({#y: A#})[#C#]{{; name=.+}}
86+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: D()[#D#]{{; name=.+}}
87+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: E({#x: A#})[#E#]{{; name=.+}}
88+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: F({#x: A#})[#F#]{{; name=.+}}
89+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: F()[#F#]{{; name=.+}}
90+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: H({#x: A#})[#H#]{{; name=.+}}
91+
// TOP_LEVEL_0-DAG: Decl[Constructor]/{{.*}}: J()[#A#]{{; name=.+}}
92+
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/{{.*}}: E()
93+
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/{{.*}}: G(
94+
// NEGATIVE_TOP_LEVEL_0-NOT: Decl[Constructor]/{{.*}}: I(
8895

8996
func testQualified0() {
9097
K.#^K_QUALIFIED_0^#
@@ -95,11 +102,11 @@ func testQualified0() {
95102
func testQualified1() {
96103
L.#^L_QUALIFIED_0^#
97104
}
105+
// L_QUALIFIED_0-NOT: X({#x: A#})
98106
// L_QUALIFIED_0-DAG: Decl[Constructor]/CurrNominal: Y({#x: A#})[#G#]{{; name=.+}}
99-
// NEGATIVE_L_QUALIFIED_0-NOT: X({#x: A#})
100107

101108
func testGenericParam<T: I, U: G>() {
102-
#^TOP_LEVEL_1^#
109+
#^TOP_LEVEL_1?check=TOP_LEVEL_0;check=GENERIC_PARAM_0^#
103110
}
104111
// GENERIC_PARAM_0-DAG: Decl[Constructor]/Local: T({#x: A#})[#I#]{{; name=.+}}
105112
// GENERIC_PARAM_0-DAG: Decl[Constructor]/Local: T({#y: A#})[#I#]{{; name=.+}}

0 commit comments

Comments
 (0)