Skip to content

Commit d2b70e4

Browse files
authored
Merge pull request #33811 from rintaro/sourcekit-completion-globalconfig
[SourceKit] Reorganize code completion options
2 parents 295b3d4 + 77b4f75 commit d2b70e4

30 files changed

+144
-154
lines changed

include/swift/IDE/CompletionInstance.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ makeCodeCompletionMemoryBuffer(const llvm::MemoryBuffer *origBuf,
3737

3838
/// Manages \c CompilerInstance for completion like operations.
3939
class CompletionInstance {
40-
unsigned MaxASTReuseCount = 100;
41-
unsigned DependencyCheckIntervalSecond = 5;
40+
struct Options {
41+
unsigned MaxASTReuseCount = 100;
42+
unsigned DependencyCheckIntervalSecond = 5;
43+
} Opts;
4244

4345
std::mutex mtx;
4446

@@ -59,7 +61,7 @@ class CompletionInstance {
5961
/// argument has changed, primary file is not the same, the \c Offset is not
6062
/// in function bodies, or the interface hash of the file has changed.
6163
bool performCachedOperationIfPossible(
62-
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
64+
llvm::hash_code ArgsHash,
6365
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
6466
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
6567
DiagnosticConsumer *DiagC,
@@ -78,7 +80,9 @@ class CompletionInstance {
7880
llvm::function_ref<void(CompilerInstance &, bool)> Callback);
7981

8082
public:
81-
void setDependencyCheckIntervalSecond(unsigned Value);
83+
CompletionInstance() {}
84+
85+
void setOptions(Options NewOpts);
8286

8387
/// Calls \p Callback with a \c CompilerInstance which is prepared for the
8488
/// second pass. \p Callback is resposible to perform the second pass on it.
@@ -94,7 +98,7 @@ class CompletionInstance {
9498
swift::CompilerInvocation &Invocation, llvm::ArrayRef<const char *> Args,
9599
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
96100
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
97-
bool EnableASTCaching, std::string &Error, DiagnosticConsumer *DiagC,
101+
std::string &Error, DiagnosticConsumer *DiagC,
98102
llvm::function_ref<void(CompilerInstance &, bool)> Callback);
99103
};
100104

lib/IDE/CompletionInstance.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static bool areAnyDependentFilesInvalidated(
275275
} // namespace
276276

277277
bool CompletionInstance::performCachedOperationIfPossible(
278-
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
278+
llvm::hash_code ArgsHash,
279279
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
280280
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
281281
DiagnosticConsumer *DiagC,
@@ -285,7 +285,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
285285

286286
if (!CachedCI)
287287
return false;
288-
if (CachedReuseCount >= MaxASTReuseCount)
288+
if (CachedReuseCount >= Opts.MaxASTReuseCount)
289289
return false;
290290
if (CachedArgHash != ArgsHash)
291291
return false;
@@ -570,20 +570,21 @@ bool CompletionInstance::shouldCheckDependencies() const {
570570
assert(CachedCI);
571571
using namespace std::chrono;
572572
auto now = system_clock::now();
573-
return DependencyCheckedTimestamp + seconds(DependencyCheckIntervalSecond) <
574-
now;
573+
auto threshold = DependencyCheckedTimestamp +
574+
seconds(Opts.DependencyCheckIntervalSecond);
575+
return threshold < now;
575576
}
576577

577-
void CompletionInstance::setDependencyCheckIntervalSecond(unsigned Value) {
578+
void CompletionInstance::setOptions(CompletionInstance::Options NewOpts) {
578579
std::lock_guard<std::mutex> lock(mtx);
579-
DependencyCheckIntervalSecond = Value;
580+
Opts = NewOpts;
580581
}
581582

582583
bool swift::ide::CompletionInstance::performOperation(
583584
swift::CompilerInvocation &Invocation, llvm::ArrayRef<const char *> Args,
584585
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
585586
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
586-
bool EnableASTCaching, std::string &Error, DiagnosticConsumer *DiagC,
587+
std::string &Error, DiagnosticConsumer *DiagC,
587588
llvm::function_ref<void(CompilerInstance &, bool)> Callback) {
588589

589590
// Always disable source location resolutions from .swiftsourceinfo file
@@ -601,29 +602,23 @@ bool swift::ide::CompletionInstance::performOperation(
601602
// We don't need token list.
602603
Invocation.getLangOptions().CollectParsedToken = false;
603604

604-
if (EnableASTCaching) {
605-
// Compute the signature of the invocation.
606-
llvm::hash_code ArgsHash(0);
607-
for (auto arg : Args)
608-
ArgsHash = llvm::hash_combine(ArgsHash, StringRef(arg));
605+
// Compute the signature of the invocation.
606+
llvm::hash_code ArgsHash(0);
607+
for (auto arg : Args)
608+
ArgsHash = llvm::hash_combine(ArgsHash, StringRef(arg));
609609

610-
// Concurrent completions will block so that they have higher chance to use
611-
// the cached completion instance.
612-
std::lock_guard<std::mutex> lock(mtx);
610+
// Concurrent completions will block so that they have higher chance to use
611+
// the cached completion instance.
612+
std::lock_guard<std::mutex> lock(mtx);
613613

614-
if (performCachedOperationIfPossible(Invocation, ArgsHash, FileSystem,
615-
completionBuffer, Offset, DiagC,
616-
Callback))
617-
return true;
614+
if (performCachedOperationIfPossible(ArgsHash, FileSystem, completionBuffer,
615+
Offset, DiagC, Callback)) {
616+
return true;
617+
}
618618

619-
if (performNewOperation(ArgsHash, Invocation, FileSystem, completionBuffer,
620-
Offset, Error, DiagC, Callback))
621-
return true;
622-
} else {
623-
// Concurrent completions may happen in parallel when caching is disabled.
624-
if (performNewOperation(None, Invocation, FileSystem, completionBuffer,
625-
Offset, Error, DiagC, Callback))
626-
return true;
619+
if(performNewOperation(ArgsHash, Invocation, FileSystem, completionBuffer,
620+
Offset, Error, DiagC, Callback)) {
621+
return true;
627622
}
628623

629624
assert(!Error.empty());

test/SourceKit/CodeComplete/complete_checkdeps_avoid_check.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func foo() {
4040
// RUN: -shell -- cp -R $INPUT_DIR/ClangFW.framework_mod/* %t/Frameworks/ClangFW.framework/ == \
4141
// RUN: -req=complete -pos=5:3 %s -- ${COMPILER_ARGS[@]} == \
4242

43-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
43+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
4444
// RUN: -shell -- echo '### Checking dependencies' == \
4545
// RUN: -req=complete -pos=5:3 %s -- ${COMPILER_ARGS[@]} \
4646

test/SourceKit/CodeComplete/complete_checkdeps_bridged.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func foo() {
2929
// RUN: %target-swift-frontend -emit-module -module-name SwiftFW -o %t/Frameworks/SwiftFW.framework/Modules/SwiftFW.swiftmodule/%target-swiftmodule-name $INPUT_DIR/SwiftFW_src/Funcs.swift
3030

3131
// RUN: %sourcekitd-test \
32-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
32+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
3333

3434
// RUN: -shell -- echo "### Initial" == \
3535
// RUN: -req=complete -pos=5:3 %s -- ${COMPILER_ARGS[@]} == \

test/SourceKit/CodeComplete/complete_checkdeps_clangmodule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func foo() {
2929
// RUN: %target-swift-frontend -emit-module -module-name SwiftFW -o %t/Frameworks/SwiftFW.framework/Modules/SwiftFW.swiftmodule/%target-swiftmodule-name $INPUT_DIR/SwiftFW_src/Funcs.swift
3030

3131
// RUN: %sourcekitd-test \
32-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
32+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
3333

3434
// RUN: -shell -- echo "### Initial" == \
3535
// RUN: -req=complete -pos=5:3 %s -- ${COMPILER_ARGS[@]} == \

test/SourceKit/CodeComplete/complete_checkdeps_otherfile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func foo() {
2929
// RUN: %target-swift-frontend -emit-module -module-name SwiftFW -o %t/Frameworks/SwiftFW.framework/Modules/SwiftFW.swiftmodule/%target-swiftmodule-name $INPUT_DIR/SwiftFW_src/Funcs.swift
3030

3131
// RUN: %sourcekitd-test \
32-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
32+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
3333

3434
// RUN: -shell -- echo "### Initial" == \
3535
// RUN: -req=complete -pos=5:3 %s -- ${COMPILER_ARGS[@]} == \

test/SourceKit/CodeComplete/complete_checkdeps_ownfile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func foo(val: MyStruct) {
4646
// RUN: cp %t/State1.swift %t/test.swift
4747

4848
// RUN: %sourcekitd-test \
49-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
49+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
5050

5151
// RUN: -shell -- echo "### Initial" == \
5252
// RUN: -req=complete -pos=5:4 %t/test.swift -- ${COMPILER_ARGS[@]} == \

test/SourceKit/CodeComplete/complete_checkdeps_swiftmodule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func foo() {
2929
// RUN: %target-swift-frontend -emit-module -module-name SwiftFW -o %t/Frameworks/SwiftFW.framework/Modules/SwiftFW.swiftmodule/%target-swiftmodule-name $INPUT_DIR/SwiftFW_src/Funcs.swift
3030

3131
// RUN: %sourcekitd-test \
32-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
32+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
3333

3434
// RUN: -shell -- echo "### Initial" == \
3535
// RUN: -req=complete -pos=5:3 %s -- ${COMPILER_ARGS[@]} == \

test/SourceKit/CodeComplete/complete_checkdeps_vfs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func foo(value: MyStruct) {
1212
// RUN: cp %S/Inputs/checkdeps/MyProject/LibraryExt.swift %t/VFS/
1313

1414
// RUN: %sourcekitd-test \
15-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
15+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
1616

1717
// RUN: -shell -- echo "### Initial" == \
1818
// 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/LibraryExt.swift %t/VFS/Library.swift == \

test/SourceKit/CodeComplete/complete_checkdeps_vfs_open.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func foo(value: MyStruct) {
1212
// RUN: cp %S/Inputs/checkdeps/MyProject/LibraryExt.swift %t/VFS/
1313

1414
// RUN: %sourcekitd-test \
15-
// RUN: -req=global-config -completion-check-dependency-interval ${DEPCHECK_INTERVAL} == \
15+
// RUN: -req=global-config -req-opts=completion_check_dependency_interval=${DEPCHECK_INTERVAL} == \
1616

1717
// RUN: -shell -- echo "### Initial" == \
1818
// 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/LibraryExt.swift %t/VFS/Library.swift == \

test/SourceKit/CodeComplete/complete_sequence.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ func bar(arg: Bar) {
1919

2020
// Disabled.
2121
// RUN: %sourcekitd-test \
22-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -- %s == \
23-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -- %s > %t.response
22+
// RUN: -req=global-config -req-opts=completion_max_astcontext_reuse_count=0 ==\
23+
// RUN: -req=complete -pos=12:11 %s -- %s == \
24+
// RUN: -req=complete -pos=15:11 %s -- %s > %t.response
2425
// RUN: %FileCheck --check-prefix=RESULT_SLOW %s < %t.response
2526

2627
// Enabled.

test/SourceKit/CodeComplete/complete_sequence_race.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ func bar(arg: Bar) {
1919

2020
// ReuseASTContext disabled.
2121
// RUN: %sourcekitd-test \
22-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -async -- %s == \
23-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -async -- %s == \
24-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -async -- %s == \
25-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -async -- %s == \
26-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=17:1 %s -async -- %s == \
27-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -async -- %s == \
28-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -async -- %s == \
29-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -async -- %s == \
30-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -async -- %s == \
31-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=17:1 %s -async -- %s == \
32-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -async -- %s == \
33-
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -async -- %s
22+
// RUN: -req=global-config -req-opts=completion_max_astcontext_reuse_count=0 \
23+
// RUN: -req=complete -pos=12:11 %s -async -- %s == \
24+
// RUN: -req=complete -pos=15:11 %s -async -- %s == \
25+
// RUN: -req=complete -pos=12:11 %s -async -- %s == \
26+
// RUN: -req=complete -pos=15:11 %s -async -- %s == \
27+
// RUN: -req=complete -pos=17:1 %s -async -- %s == \
28+
// RUN: -req=complete -pos=12:11 %s -async -- %s == \
29+
// RUN: -req=complete -pos=15:11 %s -async -- %s == \
30+
// RUN: -req=complete -pos=12:11 %s -async -- %s == \
31+
// RUN: -req=complete -pos=15:11 %s -async -- %s == \
32+
// RUN: -req=complete -pos=17:1 %s -async -- %s == \
33+
// RUN: -req=complete -pos=12:11 %s -async -- %s == \
34+
// RUN: -req=complete -pos=15:11 %s -async -- %s
3435

3536
// ReuseASTContext enabled.
3637
// RUN: %sourcekitd-test \
38+
// RUN: -req=global-config -req-opts=completion_max_astcontext_reuse_count=5 \
3739
// RUN: -req=complete -pos=12:11 %s -async -- %s == \
3840
// RUN: -req=complete -pos=15:11 %s -async -- %s == \
3941
// RUN: -req=complete -pos=12:11 %s -async -- %s == \

test/SourceKit/CodeComplete/complete_without_stdlib.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ class Str {
1010
// RUN: %empty-directory(%t/sdk)
1111

1212
// RUN: %sourcekitd-test \
13+
// RUN: -req=global-config -req-opts=completion_max_astcontext_reuse_count=0 \
1314
// RUN: -req=complete -pos=4:1 %s -- %s -resource-dir %t/rsrc -sdk %t/sdk | %FileCheck %s
1415
// RUN: %sourcekitd-test \
15-
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=4:1 %s -- %s -resource-dir %t/rsrc -sdk %t/sdk == \
16-
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=4:1 %s -- %s -resource-dir %t/rsrc -sdk %t/sdk | %FileCheck %s
16+
// RUN: -req=complete -pos=4:1 %s -- %s -resource-dir %t/rsrc -sdk %t/sdk == \
17+
// RUN: -req=complete -pos=4:1 %s -- %s -resource-dir %t/rsrc -sdk %t/sdk | %FileCheck %s
1718

1819
// CHECK: key.results: [
1920
// CHECK-NOT: key.description:

test/SourceKit/ConformingMethods/basic.swift

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

29-
// RUN: %sourcekitd-test -req=conformingmethods -pos=26:14 -repeat-request=2 %s -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD' -- -module-name MyModule %s > %t.response
29+
// RUN: %sourcekitd-test \
30+
// RUN: -req=conformingmethods -pos=26:14 -repeat-request=2 %s -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD' -- -module-name MyModule %s > %t.response
3031
// 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+
// RUN: %sourcekitd-test \
33+
// RUN: -req=global-config -req-opts=completion_max_astcontext_reuse_count=0 == \
34+
// RUN: -req=conformingmethods -pos=26:14 -repeat-request=2 %s -req-opts=expectedtypes='$s8MyModule7Target2PD;$s8MyModule7Target1PD' -- -module-name MyModule %s | %FileCheck %s --check-prefix=DISABLED
3235

3336
// DISABLED-NOT: key.reuseastcontext
3437
// DISABLED: key.members: [

test/SourceKit/CursorInfo/use-swift-source-info.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ func bar() {
1212
// RUN: %target-swift-frontend -enable-batch-mode -emit-module -emit-module-doc -emit-module-path %t/Foo.swiftmodule %t/Foo.swift -module-name Foo -emit-module-source-info-path %t/Foo.swiftsourceinfo -emit-module-doc-path %t/Foo.swiftdoc
1313
//
1414
// Test setting optimize for ide to false
15-
// RUN: %sourcekitd-test -req=global-config -for-ide=0 == -req=cursor -pos=3:3 %s -- -I %t -target %target-triple %s | %FileCheck --check-prefixes=BOTH,WITH %s
15+
// RUN: %sourcekitd-test -req=global-config -req-opts=optimize_for_ide=0 == -req=cursor -pos=3:3 %s -- -I %t -target %target-triple %s | %FileCheck --check-prefixes=BOTH,WITH %s
1616
//
1717
// Test setting optimize for ide to true
18-
// RUN: %sourcekitd-test -req=global-config -for-ide=1 == -req=cursor -pos=3:3 %s -- -I %t -target %target-triple %s | %FileCheck --check-prefixes=BOTH,WITHOUT %s
18+
// RUN: %sourcekitd-test -req=global-config -req-opts=optimize_for_ide=1 == -req=cursor -pos=3:3 %s -- -I %t -target %target-triple %s | %FileCheck --check-prefixes=BOTH,WITHOUT %s
1919
//
2020
// Test sourcekitd-test's default global configuration request (optimize for ide is true)
2121
// RUN: %sourcekitd-test -req=cursor -pos=3:3 %s -- -I %t -target %target-triple %s | %FileCheck --check-prefixes=BOTH,WITHOUT %s

test/SourceKit/TypeContextInfo/typecontext_basic.swift

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

28-
// RUN: %sourcekitd-test -req=typecontextinfo -repeat-request=2 -pos=25:22 %s -- %s > %t.response
28+
// RUN: %sourcekitd-test \
29+
// RUN: -req=typecontextinfo -repeat-request=2 -pos=25:22 %s -- %s > %t.response
2930
// 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+
// RUN: %sourcekitd-test \
32+
// RUN: -req=global-config -req-opts=completion_max_astcontext_reuse_count=0 == \
33+
// RUN: -req=typecontextinfo -repeat-request=2 -pos=25:22 %s -- %s | %FileCheck %s --check-prefix=DISABLED
3134

3235
// DISABLED-NOT: key.reuseastcontext
3336
// DISABLED: key.results: [

tools/SourceKit/include/SourceKit/Core/Context.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ namespace SourceKit {
3131
class GlobalConfig {
3232
public:
3333
struct Settings {
34-
/// When true, the default compiler options and other configuration flags will be chosen to optimize for
35-
/// usage from an IDE.
34+
/// When true, the default compiler options and other configuration flags
35+
/// will be chosen to optimize for usage from an IDE.
3636
///
3737
/// At the time of writing this just means ignoring .swiftsourceinfo files.
3838
bool OptimizeForIDE = false;
3939

40-
/// Interval second for checking dependencies in fast code completion.
41-
unsigned CompletionCheckDependencyInterval = 5;
40+
struct CompletionOptions {
41+
42+
/// Max count of reusing ASTContext for cached code completion.
43+
unsigned MaxASTContextReuseCount = 100;
44+
45+
/// Interval second for checking dependencies in cached code completion.
46+
unsigned CheckDependencyInterval = 5;
47+
} CompletionOpts;
4248
};
4349

4450
private:
@@ -47,9 +53,10 @@ class GlobalConfig {
4753

4854
public:
4955
Settings update(Optional<bool> OptimizeForIDE,
56+
Optional<unsigned> CompletionMaxASTContextReuseCount,
5057
Optional<unsigned> CompletionCheckDependencyInterval);
5158
bool shouldOptimizeForIDE() const;
52-
unsigned getCompletionCheckDependencyInterval() const;
59+
Settings::CompletionOptions getCompletionOpts() const;
5360
};
5461

5562
class Context {

tools/SourceKit/lib/Core/Context.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ using namespace SourceKit;
1818

1919
GlobalConfig::Settings
2020
GlobalConfig::update(Optional<bool> OptimizeForIDE,
21+
Optional<unsigned> CompletionMaxASTContextReuseCount,
2122
Optional<unsigned> CompletionCheckDependencyInterval) {
2223
llvm::sys::ScopedLock L(Mtx);
2324
if (OptimizeForIDE.hasValue())
2425
State.OptimizeForIDE = *OptimizeForIDE;
26+
if (CompletionMaxASTContextReuseCount.hasValue())
27+
State.CompletionOpts.MaxASTContextReuseCount =
28+
*CompletionMaxASTContextReuseCount;
2529
if (CompletionCheckDependencyInterval.hasValue())
26-
State.CompletionCheckDependencyInterval = *CompletionCheckDependencyInterval;
30+
State.CompletionOpts.CheckDependencyInterval =
31+
*CompletionCheckDependencyInterval;
2732
return State;
2833
};
2934

3035
bool GlobalConfig::shouldOptimizeForIDE() const {
3136
llvm::sys::ScopedLock L(Mtx);
3237
return State.OptimizeForIDE;
3338
}
34-
unsigned GlobalConfig::getCompletionCheckDependencyInterval() const {
39+
GlobalConfig::Settings::CompletionOptions
40+
GlobalConfig::getCompletionOpts() const {
3541
llvm::sys::ScopedLock L(Mtx);
36-
return State.CompletionCheckDependencyInterval;
42+
return State.CompletionOpts;
3743
}
3844

3945
SourceKit::Context::Context(

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct Options {
4242
bool hideLowPriority = true;
4343
bool hideByNameStyle = true;
4444
bool fuzzyMatching = true;
45-
bool reuseASTContextIfPossible = true;
4645
bool annotatedDescription = false;
4746
unsigned minFuzzyLength = 2;
4847
unsigned showTopNonLiteralResults = 3;

0 commit comments

Comments
 (0)