[CodeCompletion] Added check dependency test for complete.open

This commit is contained in:
Rintaro Ishizaki
2020-05-01 09:16:11 -07:00
parent 05a87e86c4
commit df8fa09d8e
7 changed files with 106 additions and 1 deletions

View File

@@ -1 +1,5 @@
func localSwiftFunc() -> Int {}
struct MyStruct {
func myStructMethod() {}
}

View File

@@ -1 +1,5 @@
func localSwiftFunc_mod() -> Int {}
struct MyStruct {
func myStructMethod_mod() {}
}

View File

@@ -0,0 +1,45 @@
func foo(value: MyStruct) {
value./*HERE*/
}
// RUN: DEPCHECK_INTERVAL=1
// RUN: SLEEP_TIME=2
// RUN: %empty-directory(%t)
// RUN: %sourcekitd-test \
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
// RUN: -shell -- echo "### Initial" == \
// 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 == \
// RUN: -shell -- echo "### Modify" == \
// RUN: -shell -- sleep ${SLEEP_TIME} == \
// 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 == \
// RUN: -shell -- echo "### Keep" == \
// RUN: -shell -- sleep ${SLEEP_TIME} == \
// 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 \
// RUN: | %FileCheck %s
// CHECK-LABEL: ### Initial
// CHECK: key.results: [
// CHECK-DAG: key.description: "myStructMethod()"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK-NOT: key.reusingastcontext: 1
// CHECK-LABEL: ### Modify
// CHECK: key.results: [
// CHECK-DAG: key.description: "myStructMethod_mod()"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK-NOT: key.reusingastcontext: 1
// CHECK-LABEL: ### Keep
// CHECK: key.results: [
// CHECK-DAG: key.description: "myStructMethod_mod()"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK: key.reusingastcontext: 1

View File

@@ -0,0 +1,46 @@
func foo(value: MyStruct) {
value./*HERE*/
}
// RUN: DEPCHECK_INTERVAL=1
// RUN: SLEEP_TIME=2
// RUN: %empty-directory(%t)
// RUN: %sourcekitd-test \
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
// RUN: -shell -- echo "### Initial" == \
// 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 == \
// RUN: -req=complete.close -pos=2:9 -name %t/VFS/Main.swift %s == \
// RUN: -shell -- echo "### Modify" == \
// RUN: -shell -- sleep ${SLEEP_TIME} == \
// 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 == \
// RUN: -req=complete.close -pos=2:9 -name %t/VFS/Main.swift %s == \
// RUN: -shell -- echo "### Keep" == \
// 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 == \
// RUN: -req=complete.close -pos=2:9 -name %t/VFS/Main.swift %s \
// RUN: | %FileCheck %s
// CHECK-LABEL: ### Initial
// CHECK: key.results: [
// CHECK-DAG: key.description: "myStructMethod()"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK-NOT: key.reusingastcontext: 1
// CHECK-LABEL: ### Modify
// CHECK: key.results: [
// CHECK-DAG: key.description: "myStructMethod_mod()"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK-NOT: key.reusingastcontext: 1
// CHECK-LABEL: ### Keep
// CHECK: key.results: [
// CHECK-DAG: key.description: "myStructMethod_mod()"
// CHECK-DAG: key.description: "self"
// CHECK: ]
// CHECK: key.reusingastcontext: 1

View File

@@ -146,7 +146,7 @@ public:
virtual void failed(StringRef ErrDescription) = 0;
virtual void setCompletionKind(UIdent kind) {};
virtual void setReusingASTContext(bool) {};
virtual void setReusingASTContext(bool) = 0;
virtual bool handleResult(const CodeCompletionInfo &Info) = 0;
};

View File

@@ -1221,6 +1221,7 @@ void SwiftLangSupport::codeCompleteOpen(
completionKind = completionCtx.CodeCompletionKind;
typeContextKind = completionCtx.typeContextKind;
mayUseImplicitMemberExpr = completionCtx.MayUseImplicitMemberExpr;
consumer.setReusingASTContext(completionCtx.ReusingASTContext);
completions =
extendCompletions(results, sink, info, nameToPopularity, CCOpts);
});

View File

@@ -2034,6 +2034,7 @@ public:
void startGroup(UIdent kind, StringRef name) override;
void endGroup() override;
void setNextRequestStart(unsigned offset) override;
void setReusingASTContext(bool flag) override;
};
} // end anonymous namespace
@@ -2231,6 +2232,10 @@ void SKGroupedCodeCompletionConsumer::setNextRequestStart(unsigned offset) {
assert(!Response.isNull());
Response.set(KeyNextRequestStart, offset);
}
void SKGroupedCodeCompletionConsumer::setReusingASTContext(bool flag) {
if (flag)
RespBuilder.getDictionary().setBool(KeyReusingASTContext, flag);
}
//===----------------------------------------------------------------------===//
// Type Context Info