Skip to content

Commit 30ccb52

Browse files
authored
Merge pull request swiftlang#32572 from rintaro/sourcekit-fast-completionlikereq-rdar64782333
[SourceKit] Enable ASTContext caching in other completion-like requests
2 parents 5c27465 + 33336df commit 30ccb52

File tree

15 files changed

+484
-47
lines changed

15 files changed

+484
-47
lines changed

include/swift/IDE/ConformingMethodList.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ConformingMethodListConsumer {
4242
public:
4343
virtual ~ConformingMethodListConsumer() {}
4444
virtual void handleResult(const ConformingMethodListResult &result) = 0;
45+
virtual void setReusingASTContext(bool flag) = 0;
4546
};
4647

4748
/// Printing consumer
@@ -53,6 +54,7 @@ class PrintingConformingMethodListConsumer
5354
PrintingConformingMethodListConsumer(llvm::raw_ostream &OS) : OS(OS) {}
5455

5556
void handleResult(const ConformingMethodListResult &result) override;
57+
void setReusingASTContext(bool flag) override {}
5658
};
5759

5860
/// Create a factory for code completion callbacks.

include/swift/IDE/TypeContextInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TypeContextInfoConsumer {
3838
public:
3939
virtual ~TypeContextInfoConsumer() {}
4040
virtual void handleResults(ArrayRef<TypeContextInfoItem>) = 0;
41+
virtual void setReusingASTContext(bool flag) = 0;
4142
};
4243

4344
/// Printing consumer
@@ -48,6 +49,7 @@ class PrintingTypeContextInfoConsumer : public TypeContextInfoConsumer {
4849
PrintingTypeContextInfoConsumer(llvm::raw_ostream &OS) : OS(OS) {}
4950

5051
void handleResults(ArrayRef<TypeContextInfoItem>) override;
52+
void setReusingASTContext(bool flag) override {}
5153
};
5254

5355
/// Create a factory for code completion callbacks.

test/SourceKit/ConformingMethods/basic.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,12 @@ func testing(obj: C) {
2626
let _ = obj.
2727
}
2828

29-
// RUN: %sourcekitd-test -req=conformingmethods -pos=26:14 %s -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD' -- -module-name MyModule %s > %t.response
29+
// RUN: %sourcekitd-test -req=conformingmethods -pos=26:14 -repeat-request=2 %s -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD' -- -module-name MyModule %s > %t.response
3030
// RUN: %diff -u %s.response %t.response
31+
// RUN: %sourcekitd-test -req=conformingmethods -pos=26:14 -repeat-request=2 %s -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD',reuseastcontext=0 -- -module-name MyModule %s | %FileCheck %s --check-prefix=DISABLED
32+
33+
// DISABLED-NOT: key.reuseastcontext
34+
// DISABLED: key.members: [
35+
// DISABLED-NOT: key.reuseastcontext
36+
// DISABLED: key.members: [
37+
// DISABLED-NOT: key.reuseastcontext

test/SourceKit/ConformingMethods/basic.swift.response

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,24 @@
1818
}
1919
]
2020
}
21+
{
22+
key.typename: "C",
23+
key.typeusr: "$s8MyModule1CCD",
24+
key.members: [
25+
{
26+
key.name: "methodForTarget1()",
27+
key.sourcetext: "methodForTarget1()",
28+
key.description: "methodForTarget1()",
29+
key.typename: "ConcreteTarget1",
30+
key.typeusr: "$s8MyModule15ConcreteTarget1VD"
31+
},
32+
{
33+
key.name: "methodForTarget2()",
34+
key.sourcetext: "methodForTarget2()",
35+
key.description: "methodForTarget2()",
36+
key.typename: "ConcreteTarget2",
37+
key.typeusr: "$s8MyModule15ConcreteTarget2VD"
38+
}
39+
],
40+
key.reusingastcontext: 1
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
protocol Target1 {}
2+
protocol Target2 {}
3+
protocol Target3 {}
4+
5+
struct ConcreteTarget1 : Target1 {}
6+
struct ConcreteTarget2 : Target2 {}
7+
struct ConcreteTarget3 : Target3 {}
8+
9+
protocol P {
10+
associatedtype Assoc
11+
func protocolMethod(asc: Assoc) -> Self
12+
}
13+
extension P {
14+
func protocolMethod(asc: Assoc) -> Self { return self }
15+
}
16+
enum MyEnum {
17+
case foo, bar
18+
}
19+
20+
class C : P {
21+
typealias Assoc = String
22+
static func staticMethod() -> Self {}
23+
func instanceMethod(x: MyEnum) -> C {}
24+
func methodForTarget1() -> ConcreteTarget1 {}
25+
func methodForTarget2() -> ConcreteTarget2 {}
26+
}
27+
28+
func testing(obj: C) {
29+
let _ = obj.
30+
}
31+
func testing(obj: C) {
32+
let _ = obj.instanceMethod(x: )
33+
}
34+
35+
36+
// RUN: %sourcekitd-test \
37+
// RUN: -req=complete -pos=29:14 %s -- %s -module-name MyModule == \
38+
// RUN: -req=conformingmethods -pos=29:14 -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD' %s -- %s -module-name MyModule == \
39+
// RUN: -req=typecontextinfo -pos=32:33 %s -- %s -module-name MyModule == \
40+
// RUN: -req=complete -pos=29:14 %s -- %s -module-name MyModule > %t.response
41+
// RUN: %diff -u %s.response %t.response
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
{
2+
key.results: [
3+
{
4+
key.kind: source.lang.swift.decl.function.operator.infix,
5+
key.name: "!==",
6+
key.sourcetext: " !== <#T##AnyObject?#>",
7+
key.description: "!==",
8+
key.typename: "Bool",
9+
key.context: source.codecompletion.context.othermodule,
10+
key.typerelation: source.codecompletion.typerelation.unknown,
11+
key.num_bytes_to_erase: 0,
12+
key.is_system: 1,
13+
key.modulename: "Swift"
14+
},
15+
{
16+
key.kind: source.lang.swift.decl.function.operator.infix,
17+
key.name: "===",
18+
key.sourcetext: " === <#T##AnyObject?#>",
19+
key.description: "===",
20+
key.typename: "Bool",
21+
key.context: source.codecompletion.context.othermodule,
22+
key.typerelation: source.codecompletion.typerelation.unknown,
23+
key.num_bytes_to_erase: 0,
24+
key.is_system: 1,
25+
key.modulename: "Swift"
26+
},
27+
{
28+
key.kind: source.lang.swift.decl.function.method.instance,
29+
key.name: "instanceMethod(x:)",
30+
key.sourcetext: ".instanceMethod(x: <#T##MyEnum#>)",
31+
key.description: "instanceMethod(x: MyEnum)",
32+
key.typename: "C",
33+
key.context: source.codecompletion.context.thisclass,
34+
key.typerelation: source.codecompletion.typerelation.unknown,
35+
key.num_bytes_to_erase: 0,
36+
key.associated_usrs: "s:8MyModule1CC14instanceMethod1xAcA0A4EnumO_tF",
37+
key.modulename: "MyModule"
38+
},
39+
{
40+
key.kind: source.lang.swift.decl.function.method.instance,
41+
key.name: "methodForTarget1()",
42+
key.sourcetext: ".methodForTarget1()",
43+
key.description: "methodForTarget1()",
44+
key.typename: "ConcreteTarget1",
45+
key.context: source.codecompletion.context.thisclass,
46+
key.typerelation: source.codecompletion.typerelation.unknown,
47+
key.num_bytes_to_erase: 0,
48+
key.associated_usrs: "s:8MyModule1CC16methodForTarget1AA08ConcreteE0VyF",
49+
key.modulename: "MyModule"
50+
},
51+
{
52+
key.kind: source.lang.swift.decl.function.method.instance,
53+
key.name: "methodForTarget2()",
54+
key.sourcetext: ".methodForTarget2()",
55+
key.description: "methodForTarget2()",
56+
key.typename: "ConcreteTarget2",
57+
key.context: source.codecompletion.context.thisclass,
58+
key.typerelation: source.codecompletion.typerelation.unknown,
59+
key.num_bytes_to_erase: 0,
60+
key.associated_usrs: "s:8MyModule1CC16methodForTarget2AA08ConcreteE0VyF",
61+
key.modulename: "MyModule"
62+
},
63+
{
64+
key.kind: source.lang.swift.decl.function.method.instance,
65+
key.name: "protocolMethod(asc:)",
66+
key.sourcetext: ".protocolMethod(asc: <#T##String#>)",
67+
key.description: "protocolMethod(asc: String)",
68+
key.typename: "C",
69+
key.context: source.codecompletion.context.superclass,
70+
key.typerelation: source.codecompletion.typerelation.unknown,
71+
key.num_bytes_to_erase: 0,
72+
key.associated_usrs: "s:8MyModule1PPAAE14protocolMethod3ascx5AssocQz_tF",
73+
key.modulename: "MyModule"
74+
},
75+
{
76+
key.kind: source.lang.swift.keyword,
77+
key.name: "self",
78+
key.sourcetext: ".self",
79+
key.description: "self",
80+
key.typename: "C",
81+
key.context: source.codecompletion.context.thisclass,
82+
key.typerelation: source.codecompletion.typerelation.unknown,
83+
key.num_bytes_to_erase: 0
84+
}
85+
]
86+
}
87+
{
88+
key.typename: "C",
89+
key.typeusr: "$s8MyModule1CCD",
90+
key.members: [
91+
{
92+
key.name: "methodForTarget1()",
93+
key.sourcetext: "methodForTarget1()",
94+
key.description: "methodForTarget1()",
95+
key.typename: "ConcreteTarget1",
96+
key.typeusr: "$s8MyModule15ConcreteTarget1VD"
97+
},
98+
{
99+
key.name: "methodForTarget2()",
100+
key.sourcetext: "methodForTarget2()",
101+
key.description: "methodForTarget2()",
102+
key.typename: "ConcreteTarget2",
103+
key.typeusr: "$s8MyModule15ConcreteTarget2VD"
104+
}
105+
],
106+
key.reusingastcontext: 1
107+
}
108+
{
109+
key.results: [
110+
{
111+
key.typename: "MyEnum",
112+
key.typeusr: "$s8MyModule0A4EnumOD",
113+
key.implicitmembers: [
114+
{
115+
key.name: "foo",
116+
key.sourcetext: "foo",
117+
key.description: "foo"
118+
},
119+
{
120+
key.name: "bar",
121+
key.sourcetext: "bar",
122+
key.description: "bar"
123+
}
124+
]
125+
}
126+
],
127+
key.reusingastcontext: 1
128+
}
129+
{
130+
key.results: [
131+
{
132+
key.kind: source.lang.swift.decl.function.operator.infix,
133+
key.name: "!==",
134+
key.sourcetext: " !== <#T##AnyObject?#>",
135+
key.description: "!==",
136+
key.typename: "Bool",
137+
key.context: source.codecompletion.context.othermodule,
138+
key.typerelation: source.codecompletion.typerelation.unknown,
139+
key.num_bytes_to_erase: 0,
140+
key.is_system: 1,
141+
key.modulename: "Swift"
142+
},
143+
{
144+
key.kind: source.lang.swift.decl.function.operator.infix,
145+
key.name: "===",
146+
key.sourcetext: " === <#T##AnyObject?#>",
147+
key.description: "===",
148+
key.typename: "Bool",
149+
key.context: source.codecompletion.context.othermodule,
150+
key.typerelation: source.codecompletion.typerelation.unknown,
151+
key.num_bytes_to_erase: 0,
152+
key.is_system: 1,
153+
key.modulename: "Swift"
154+
},
155+
{
156+
key.kind: source.lang.swift.decl.function.method.instance,
157+
key.name: "instanceMethod(x:)",
158+
key.sourcetext: ".instanceMethod(x: <#T##MyEnum#>)",
159+
key.description: "instanceMethod(x: MyEnum)",
160+
key.typename: "C",
161+
key.context: source.codecompletion.context.thisclass,
162+
key.typerelation: source.codecompletion.typerelation.unknown,
163+
key.num_bytes_to_erase: 0,
164+
key.associated_usrs: "s:8MyModule1CC14instanceMethod1xAcA0A4EnumO_tF",
165+
key.modulename: "MyModule"
166+
},
167+
{
168+
key.kind: source.lang.swift.decl.function.method.instance,
169+
key.name: "methodForTarget1()",
170+
key.sourcetext: ".methodForTarget1()",
171+
key.description: "methodForTarget1()",
172+
key.typename: "ConcreteTarget1",
173+
key.context: source.codecompletion.context.thisclass,
174+
key.typerelation: source.codecompletion.typerelation.unknown,
175+
key.num_bytes_to_erase: 0,
176+
key.associated_usrs: "s:8MyModule1CC16methodForTarget1AA08ConcreteE0VyF",
177+
key.modulename: "MyModule"
178+
},
179+
{
180+
key.kind: source.lang.swift.decl.function.method.instance,
181+
key.name: "methodForTarget2()",
182+
key.sourcetext: ".methodForTarget2()",
183+
key.description: "methodForTarget2()",
184+
key.typename: "ConcreteTarget2",
185+
key.context: source.codecompletion.context.thisclass,
186+
key.typerelation: source.codecompletion.typerelation.unknown,
187+
key.num_bytes_to_erase: 0,
188+
key.associated_usrs: "s:8MyModule1CC16methodForTarget2AA08ConcreteE0VyF",
189+
key.modulename: "MyModule"
190+
},
191+
{
192+
key.kind: source.lang.swift.decl.function.method.instance,
193+
key.name: "protocolMethod(asc:)",
194+
key.sourcetext: ".protocolMethod(asc: <#T##String#>)",
195+
key.description: "protocolMethod(asc: String)",
196+
key.typename: "C",
197+
key.context: source.codecompletion.context.superclass,
198+
key.typerelation: source.codecompletion.typerelation.unknown,
199+
key.num_bytes_to_erase: 0,
200+
key.associated_usrs: "s:8MyModule1PPAAE14protocolMethod3ascx5AssocQz_tF",
201+
key.modulename: "MyModule"
202+
},
203+
{
204+
key.kind: source.lang.swift.keyword,
205+
key.name: "self",
206+
key.sourcetext: ".self",
207+
key.description: "self",
208+
key.typename: "C",
209+
key.context: source.codecompletion.context.thisclass,
210+
key.typerelation: source.codecompletion.typerelation.unknown,
211+
key.num_bytes_to_erase: 0
212+
}
213+
],
214+
key.reusingastcontext: 1
215+
}

test/SourceKit/TypeContextInfo/typecontext_basic.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,12 @@ func test(obj: C) {
2525
let _ = obj.foo(x:
2626
}
2727

28-
// RUN: %sourcekitd-test -req=typecontextinfo -pos=25:22 %s -- %s > %t.response
28+
// RUN: %sourcekitd-test -req=typecontextinfo -repeat-request=2 -pos=25:22 %s -- %s > %t.response
2929
// RUN: %diff -u %s.response %t.response
30+
// RUN: %sourcekitd-test -req=typecontextinfo -repeat-request=2 -pos=25:22 %s -req-opts=reuseastcontext=0 -- %s | %FileCheck %s --check-prefix=DISABLED
31+
32+
// DISABLED-NOT: key.reuseastcontext
33+
// DISABLED: key.results: [
34+
// DISABLED-NOT: key.reuseastcontext
35+
// DISABLED: key.results: [
36+
// DISABLED-NOT: key.reuseastcontext

0 commit comments

Comments
 (0)