Skip to content

Commit df8fa09

Browse files
committed
[CodeCompletion] Added check dependency test for complete.open
1 parent 05a87e8 commit df8fa09

File tree

7 files changed

+106
-1
lines changed

7 files changed

+106
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
func localSwiftFunc() -> Int {}
2+
3+
struct MyStruct {
4+
func myStructMethod() {}
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
func localSwiftFunc_mod() -> Int {}
2+
3+
struct MyStruct {
4+
func myStructMethod_mod() {}
5+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
func foo(value: MyStruct) {
2+
value./*HERE*/
3+
}
4+
5+
// RUN: DEPCHECK_INTERVAL=1
6+
// RUN: SLEEP_TIME=2
7+
8+
// RUN: %empty-directory(%t)
9+
10+
// RUN: %sourcekitd-test \
11+
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
12+
13+
// RUN: -shell -- echo "### Initial" == \
14+
// RUN: -req=complete -pos=2:9 -pass-as-sourcetext -vfs-files=%t/VFS/Main.swift=@%s,%t/VFS/Library.swift=@%S/Inputs/checkdeps/MyProject/Library.swift %t/VFS/Main.swift -- -target %target-triple %t/VFS/Main.swift %t/VFS/Library.swift == \
15+
16+
// RUN: -shell -- echo "### Modify" == \
17+
// RUN: -shell -- sleep ${SLEEP_TIME} == \
18+
// RUN: -req=complete -pos=2:9 -pass-as-sourcetext -vfs-files=%t/VFS/Main.swift=@%s,%t/VFS/Library.swift=@%S/Inputs/checkdeps/MyProject_mod/Library.swift %t/VFS/Main.swift -- -target %target-triple %t/VFS/Main.swift %t/VFS/Library.swift == \
19+
20+
// RUN: -shell -- echo "### Keep" == \
21+
// RUN: -shell -- sleep ${SLEEP_TIME} == \
22+
// RUN: -req=complete -pos=2:9 -pass-as-sourcetext -vfs-files=%t/VFS/Main.swift=@%s,%t/VFS/Library.swift=@%S/Inputs/checkdeps/MyProject_mod/Library.swift %t/VFS/Main.swift -- -target %target-triple %t/VFS/Main.swift %t/VFS/Library.swift \
23+
24+
// RUN: | %FileCheck %s
25+
26+
// CHECK-LABEL: ### Initial
27+
// CHECK: key.results: [
28+
// CHECK-DAG: key.description: "myStructMethod()"
29+
// CHECK-DAG: key.description: "self"
30+
// CHECK: ]
31+
// CHECK-NOT: key.reusingastcontext: 1
32+
33+
// CHECK-LABEL: ### Modify
34+
// CHECK: key.results: [
35+
// CHECK-DAG: key.description: "myStructMethod_mod()"
36+
// CHECK-DAG: key.description: "self"
37+
// CHECK: ]
38+
// CHECK-NOT: key.reusingastcontext: 1
39+
40+
// CHECK-LABEL: ### Keep
41+
// CHECK: key.results: [
42+
// CHECK-DAG: key.description: "myStructMethod_mod()"
43+
// CHECK-DAG: key.description: "self"
44+
// CHECK: ]
45+
// CHECK: key.reusingastcontext: 1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
func foo(value: MyStruct) {
2+
value./*HERE*/
3+
}
4+
5+
// RUN: DEPCHECK_INTERVAL=1
6+
// RUN: SLEEP_TIME=2
7+
8+
// RUN: %empty-directory(%t)
9+
// RUN: %sourcekitd-test \
10+
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
11+
12+
// RUN: -shell -- echo "### Initial" == \
13+
// RUN: -req=complete.open -pos=2:9 -pass-as-sourcetext -vfs-files=%t/VFS/Main.swift=@%s,%t/VFS/Library.swift=@%S/Inputs/checkdeps/MyProject/Library.swift %t/VFS/Main.swift -- -target %target-triple %t/VFS/Main.swift %t/VFS/Library.swift == \
14+
// RUN: -req=complete.close -pos=2:9 -name %t/VFS/Main.swift %s == \
15+
16+
// RUN: -shell -- echo "### Modify" == \
17+
// RUN: -shell -- sleep ${SLEEP_TIME} == \
18+
// RUN: -req=complete.open -pos=2:9 -pass-as-sourcetext -vfs-files=%t/VFS/Main.swift=@%s,%t/VFS/Library.swift=@%S/Inputs/checkdeps/MyProject_mod/Library.swift %t/VFS/Main.swift -- -target %target-triple %t/VFS/Main.swift %t/VFS/Library.swift == \
19+
// RUN: -req=complete.close -pos=2:9 -name %t/VFS/Main.swift %s == \
20+
21+
// RUN: -shell -- echo "### Keep" == \
22+
// RUN: -req=complete.open -pos=2:9 -pass-as-sourcetext -vfs-files=%t/VFS/Main.swift=@%s,%t/VFS/Library.swift=@%S/Inputs/checkdeps/MyProject_mod/Library.swift %t/VFS/Main.swift -- -target %target-triple %t/VFS/Main.swift %t/VFS/Library.swift == \
23+
// RUN: -req=complete.close -pos=2:9 -name %t/VFS/Main.swift %s \
24+
25+
// RUN: | %FileCheck %s
26+
27+
// CHECK-LABEL: ### Initial
28+
// CHECK: key.results: [
29+
// CHECK-DAG: key.description: "myStructMethod()"
30+
// CHECK-DAG: key.description: "self"
31+
// CHECK: ]
32+
// CHECK-NOT: key.reusingastcontext: 1
33+
34+
// CHECK-LABEL: ### Modify
35+
// CHECK: key.results: [
36+
// CHECK-DAG: key.description: "myStructMethod_mod()"
37+
// CHECK-DAG: key.description: "self"
38+
// CHECK: ]
39+
// CHECK-NOT: key.reusingastcontext: 1
40+
41+
// CHECK-LABEL: ### Keep
42+
// CHECK: key.results: [
43+
// CHECK-DAG: key.description: "myStructMethod_mod()"
44+
// CHECK-DAG: key.description: "self"
45+
// CHECK: ]
46+
// CHECK: key.reusingastcontext: 1

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class CodeCompletionConsumer {
146146
virtual void failed(StringRef ErrDescription) = 0;
147147

148148
virtual void setCompletionKind(UIdent kind) {};
149-
virtual void setReusingASTContext(bool) {};
149+
virtual void setReusingASTContext(bool) = 0;
150150
virtual bool handleResult(const CodeCompletionInfo &Info) = 0;
151151
};
152152

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ void SwiftLangSupport::codeCompleteOpen(
12211221
completionKind = completionCtx.CodeCompletionKind;
12221222
typeContextKind = completionCtx.typeContextKind;
12231223
mayUseImplicitMemberExpr = completionCtx.MayUseImplicitMemberExpr;
1224+
consumer.setReusingASTContext(completionCtx.ReusingASTContext);
12241225
completions =
12251226
extendCompletions(results, sink, info, nameToPopularity, CCOpts);
12261227
});

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,7 @@ class SKGroupedCodeCompletionConsumer : public GroupedCodeCompletionConsumer {
20342034
void startGroup(UIdent kind, StringRef name) override;
20352035
void endGroup() override;
20362036
void setNextRequestStart(unsigned offset) override;
2037+
void setReusingASTContext(bool flag) override;
20372038
};
20382039
} // end anonymous namespace
20392040

@@ -2231,6 +2232,10 @@ void SKGroupedCodeCompletionConsumer::setNextRequestStart(unsigned offset) {
22312232
assert(!Response.isNull());
22322233
Response.set(KeyNextRequestStart, offset);
22332234
}
2235+
void SKGroupedCodeCompletionConsumer::setReusingASTContext(bool flag) {
2236+
if (flag)
2237+
RespBuilder.getDictionary().setBool(KeyReusingASTContext, flag);
2238+
}
22342239

22352240
//===----------------------------------------------------------------------===//
22362241
// Type Context Info

0 commit comments

Comments
 (0)