Skip to content

[SourceKit] Don't use diagnostics to indicate fast-completion #30865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/IDE/CodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,11 @@ class CodeCompletionContext {
/// e.g. `x = .foo`.
bool MayUseImplicitMemberExpr = false;

/// Flag to indicate that the completion is happening reusing ASTContext
/// from the previous completion.
/// NOTE: Do not use this to change the behavior. This is only for debugging.
bool ReusingASTContext = false;

CodeCompletionContext(CodeCompletionCache &Cache)
: Cache(Cache) {}

Expand Down
6 changes: 3 additions & 3 deletions include/swift/IDE/CompletionInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CompletionInstance {
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &)> Callback);
llvm::function_ref<void(CompilerInstance &, bool)> Callback);

/// Calls \p Callback with new \c CompilerInstance for the completion
/// request. The \c CompilerInstace passed to the callback already performed
Expand All @@ -66,7 +66,7 @@ class CompletionInstance {
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
std::string &Error, DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &)> Callback);
llvm::function_ref<void(CompilerInstance &, bool)> Callback);

public:
/// Calls \p Callback with a \c CompilerInstance which is prepared for the
Expand All @@ -84,7 +84,7 @@ class CompletionInstance {
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
bool EnableASTCaching, std::string &Error, DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &)> Callback);
llvm::function_ref<void(CompilerInstance &, bool)> Callback);
};

} // namespace ide
Expand Down
13 changes: 5 additions & 8 deletions lib/IDE/CompletionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &)> Callback) {
llvm::function_ref<void(CompilerInstance &, bool)> Callback) {

if (!CachedCI)
return false;
Expand Down Expand Up @@ -344,10 +344,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
if (DiagC)
CI.addDiagnosticConsumer(DiagC);

CI.getDiags().diagnose(SM.getLocForOffset(newBufferID, newInfo.StartOffset),
diag::completion_reusing_astcontext);

Callback(CI);
Callback(CI, /*reusingASTContext=*/true);

if (DiagC)
CI.removeDiagnosticConsumer(DiagC);
Expand All @@ -362,7 +359,7 @@ bool CompletionInstance::performNewOperation(
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
std::string &Error, DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &)> Callback) {
llvm::function_ref<void(CompilerInstance &, bool)> Callback) {

auto TheInstance = std::make_unique<CompilerInstance>();
{
Expand Down Expand Up @@ -399,7 +396,7 @@ bool CompletionInstance::performNewOperation(
if (!state->hasCodeCompletionDelayedDeclState())
return true;

Callback(CI);
Callback(CI, /*reusingASTContext=*/false);
}

if (ArgsHash.hasValue()) {
Expand All @@ -416,7 +413,7 @@ bool swift::ide::CompletionInstance::performOperation(
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
bool EnableASTCaching, std::string &Error, DiagnosticConsumer *DiagC,
llvm::function_ref<void(CompilerInstance &)> Callback) {
llvm::function_ref<void(CompilerInstance &, bool)> Callback) {

// Always disable source location resolutions from .swiftsourceinfo file
// because they're somewhat heavy operations and aren't needed for completion.
Expand Down
62 changes: 33 additions & 29 deletions test/SourceKit/CodeComplete/complete_sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,51 @@ func bar(arg: Bar) {

// Disabled.
// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -- %s == \
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -- %s > %t.response
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
// RUN: %FileCheck --check-prefix=TRACE_NORMAL %s < %t.response
// RUN: %FileCheck --check-prefix=RESULT_SLOW %s < %t.response

// Enabled.
// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=12:11 %s -- %s == \
// RUN: -req=complete -pos=15:11 %s -- %s > %t.response.reuseastcontext
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.reuseastcontext
// RUN: %FileCheck --check-prefix=TRACE_REUSEAST %s < %t.response.reuseastcontext
// RUN: %FileCheck --check-prefix=RESULT_FAST %s < %t.response.reuseastcontext

// Enabled - compiler argument mismatch.
// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=12:11 %s -- %s -DNOTUSED == \
// RUN: -req=complete -pos=15:11 %s -- -DNOTUSED %s > %t.response.reuseastcontext_argmismatch
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.reuseastcontext_argmismatch
// RUN: %FileCheck --check-prefix=TRACE_NORMAL %s < %t.response.reuseastcontext_argmismatch
// RUN: %FileCheck --check-prefix=RESULT_SLOW %s < %t.response.reuseastcontext_argmismatch

// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "barMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]
// RESULT_SLOW-LABEL: key.results: [
// RESULT_SLOW-DAG: key.name: "fooMethod()"
// RESULT_SLOW-DAG: key.name: "self"
// RESULT_SLOW-DAG: key.name: "x"
// RESULT_SLOW-DAG: key.name: "y"
// RESULT_SLOW: ]
// RESULT_SLOW-NOT: key.reusingastcontext: 1

// TRACE_NORMAL-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE_NORMAL-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE_NORMAL-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE_NORMAL-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// RESULT_SLOW-LABEL: key.results: [
// RESULT_SLOW-DAG: key.name: "barMethod()"
// RESULT_SLOW-DAG: key.name: "self"
// RESULT_SLOW-DAG: key.name: "a"
// RESULT_SLOW-DAG: key.name: "b"
// RESULT_SLOW: ]
// RESULT_SLOW-NOT: key.reusingastcontext: 1

// TRACE_REUSEAST-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE_REUSEAST-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE_REUSEAST-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE_REUSEAST: key.description: "completion reusing previous ASTContext (benign diagnostic)"

// RESULT_FAST-LABEL: key.results: [
// RESULT_FAST-DAG: key.name: "fooMethod()"
// RESULT_FAST-DAG: key.name: "self"
// RESULT_FAST-DAG: key.name: "x"
// RESULT_FAST-DAG: key.name: "y"
// RESULT_FAST: ]
// RESULT_FAST-NOT: key.reusingastcontext: 1

// RESULT_FAST-LABEL: key.results: [
// RESULT_FAST-DAG: key.name: "barMethod()"
// RESULT_FAST-DAG: key.name: "self"
// RESULT_FAST-DAG: key.name: "a"
// RESULT_FAST-DAG: key.name: "b"
// RESULT_FAST: ]
// RESULT_FAST: key.reusingastcontext: 1
51 changes: 23 additions & 28 deletions test/SourceKit/CodeComplete/complete_sequence_accessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ enum S {

// Enabled.
// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=12:9 %s -- %s -parse-as-library == \
// RUN: -req=complete -pos=15:15 %s -- %s -parse-as-library == \
// RUN: -req=complete -pos=16:15 %s -- %s -parse-as-library == \
Expand All @@ -52,7 +51,6 @@ enum S {
// RUN: -req=complete -pos=23:1 %s -- %s -parse-as-library == \
// RUN: -req=complete -pos=16:1 %s -- %s -parse-as-library > %t.response
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response

// globalValImplicit
// RESULT-LABEL: key.results: [
Expand All @@ -61,62 +59,80 @@ enum S {
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]
// RESULT-NOT: key.reusingastcontext: 1

// globalValGetSet(get)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// globalValGetSet(set)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "barMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// propertyImplicit
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// propertyGetSet(get)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "barMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// propertyGetSet(set)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// subscript(implicit getter)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// subscript(get)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "barMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// subscript(set)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "barMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// accessor top (global var)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.description: "get"
Expand All @@ -125,6 +141,8 @@ enum S {
// RESULT-DAG: key.description: "didSet"
// RESULT-DAG: key.description: "Foo"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// accessor top (property)
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.description: "get"
Expand All @@ -133,6 +151,8 @@ enum S {
// RESULT-DAG: key.description: "didSet"
// RESULT-DAG: key.description: "Foo"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// accessor second (global var)
// RESULT-LABEL: key.results: [
// RESULT-NOT: key.description: "Foo"
Expand All @@ -141,29 +161,4 @@ enum S {
// RESULT-DAG: key.description: "willSet"
// RESULT-DAG: key.description: "didSet"
// RESULT: ]


// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// RESULT-NOT: key.reusingastcontext: 1
9 changes: 5 additions & 4 deletions test/SourceKit/CodeComplete/complete_sequence_crossfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,28 @@ extension Bar {

// BEGIN dummy.swift

// NOTE: Test that switching editing file doesn't trigger fast-completion

// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s

// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=7:11 %t/file1.swift -- %t/file1.swift %t/file2.swift == \
// RUN: -req=complete -pos=6:11 %t/file2.swift -- %t/file1.swift %t/file2.swift > %t.response
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response

// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT-NOT: key.reusingastcontext: 1

// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "barMethod()"
// RESULT-DAG: key.name: "self"
// RESULT-DAG: key.name: "a"
// RESULT-DAG: key.name: "b"
// RESULT: ]

// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// RESULT-NOT: key.reusingastcontext: 1
18 changes: 3 additions & 15 deletions test/SourceKit/CodeComplete/complete_sequence_edit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ func foo(arg: Foo) {
// RUN: %{python} %utils/split_file.py -o %t %s

// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -pos=8:11 -name file.swift -text-input %t/State1.swift -- file.swift == \
// RUN: -req=complete -pos=11:13 -name file.swift -text-input %t/State2.swift -- file.swift == \
// RUN: -req=complete -pos=12:13 -name file.swift -text-input %t/State3.swift -- file.swift > %t.response
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response

// RESULT-LABEL: key.results: [
// RESULT-NOT: key.name: "z"
Expand All @@ -58,6 +56,7 @@ func foo(arg: Foo) {
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT-NOT: key.reusingastcontext: 1

// RESULT-LABEL: key.results: [
// RESULT-NOT: key.name: "z"
Expand All @@ -66,6 +65,7 @@ func foo(arg: Foo) {
// RESULT-DAG: key.name: "x"
// RESULT-DAG: key.name: "y"
// RESULT: ]
// RESULT: key.reusingastcontext: 1

// RESULT-LABEL: key.results: [
// RESULT-DAG: key.name: "fooMethod()"
Expand All @@ -74,16 +74,4 @@ func foo(arg: Foo) {
// RESULT-DAG: key.name: "y"
// RESULT-DAG: key.name: "z"
// RESULT: ]

// TRACE: key.notification: source.notification.compile-did-finish,
// TRACE-NEXT: key.diagnostics: [
// TRACE-NEXT: ]

// TRACE: key.notification: source.notification.compile-did-finish,
// TRACE-NEXT: key.diagnostics: [
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE: ]

// TRACE: key.notification: source.notification.compile-did-finish,
// TRACE-NEXT: key.diagnostics: [
// TRACE-NEXT: ]
// RESULT-NOT: key.reusingastcontext: 1
Loading