Skip to content

Commit 4870d1c

Browse files
committed
[SourceKit] Don't use diagnostics to indicate fast-completion
Add 'key.reusingastcontext: 1' to the response instead. Using diagnostics can be a noise to indexing log clients. rdar://problem/61367416
1 parent 31e7873 commit 4870d1c

22 files changed

+149
-163
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ class CodeCompletionContext {
856856
/// e.g. `x = .foo`.
857857
bool MayUseImplicitMemberExpr = false;
858858

859+
/// Flag to indicate that the completion is happening reusing ASTContext
860+
/// from the previous completion.
861+
/// NOTE: Do not use this to change the behavior. This is only for debugging.
862+
bool ReusingASTContext = false;
863+
859864
CodeCompletionContext(CodeCompletionCache &Cache)
860865
: Cache(Cache) {}
861866

include/swift/IDE/CompletionInstance.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CompletionInstance {
5454
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
5555
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
5656
DiagnosticConsumer *DiagC,
57-
llvm::function_ref<void(CompilerInstance &)> Callback);
57+
llvm::function_ref<void(CompilerInstance &, bool)> Callback);
5858

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

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

9090
} // namespace ide

lib/IDE/CompletionInstance.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
166166
const swift::CompilerInvocation &Invocation, llvm::hash_code ArgsHash,
167167
llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
168168
DiagnosticConsumer *DiagC,
169-
llvm::function_ref<void(CompilerInstance &)> Callback) {
169+
llvm::function_ref<void(CompilerInstance &, bool)> Callback) {
170170

171171
if (!CachedCI)
172172
return false;
@@ -344,10 +344,7 @@ bool CompletionInstance::performCachedOperaitonIfPossible(
344344
if (DiagC)
345345
CI.addDiagnosticConsumer(DiagC);
346346

347-
CI.getDiags().diagnose(SM.getLocForOffset(newBufferID, newInfo.StartOffset),
348-
diag::completion_reusing_astcontext);
349-
350-
Callback(CI);
347+
Callback(CI, /*reusingASTContext=*/true);
351348

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

367364
auto TheInstance = std::make_unique<CompilerInstance>();
368365
{
@@ -399,7 +396,7 @@ bool CompletionInstance::performNewOperation(
399396
if (!state->hasCodeCompletionDelayedDeclState())
400397
return true;
401398

402-
Callback(CI);
399+
Callback(CI, /*reusingASTContext=*/false);
403400
}
404401

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

421418
// Always disable source location resolutions from .swiftsourceinfo file
422419
// because they're somewhat heavy operations and aren't needed for completion.

test/SourceKit/CodeComplete/complete_sequence.swift

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,51 @@ func bar(arg: Bar) {
1919

2020
// Disabled.
2121
// RUN: %sourcekitd-test \
22-
// RUN: -req=track-compiles == \
2322
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=12:11 %s -- %s == \
2423
// RUN: -req=complete -req-opts=reuseastcontext=0 -pos=15:11 %s -- %s > %t.response
25-
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
26-
// RUN: %FileCheck --check-prefix=TRACE_NORMAL %s < %t.response
24+
// RUN: %FileCheck --check-prefix=RESULT_SLOW %s < %t.response
2725

2826
// Enabled.
2927
// RUN: %sourcekitd-test \
30-
// RUN: -req=track-compiles == \
3128
// RUN: -req=complete -pos=12:11 %s -- %s == \
3229
// RUN: -req=complete -pos=15:11 %s -- %s > %t.response.reuseastcontext
33-
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.reuseastcontext
34-
// RUN: %FileCheck --check-prefix=TRACE_REUSEAST %s < %t.response.reuseastcontext
30+
// RUN: %FileCheck --check-prefix=RESULT_FAST %s < %t.response.reuseastcontext
3531

3632
// Enabled - compiler argument mismatch.
3733
// RUN: %sourcekitd-test \
38-
// RUN: -req=track-compiles == \
3934
// RUN: -req=complete -pos=12:11 %s -- %s -DNOTUSED == \
4035
// RUN: -req=complete -pos=15:11 %s -- -DNOTUSED %s > %t.response.reuseastcontext_argmismatch
41-
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response.reuseastcontext_argmismatch
42-
// RUN: %FileCheck --check-prefix=TRACE_NORMAL %s < %t.response.reuseastcontext_argmismatch
36+
// RUN: %FileCheck --check-prefix=RESULT_SLOW %s < %t.response.reuseastcontext_argmismatch
4337

44-
// RESULT-LABEL: key.results: [
45-
// RESULT-DAG: key.name: "fooMethod()"
46-
// RESULT-DAG: key.name: "self"
47-
// RESULT-DAG: key.name: "x"
48-
// RESULT-DAG: key.name: "y"
49-
// RESULT: ]
50-
// RESULT-LABEL: key.results: [
51-
// RESULT-DAG: key.name: "barMethod()"
52-
// RESULT-DAG: key.name: "self"
53-
// RESULT-DAG: key.name: "a"
54-
// RESULT-DAG: key.name: "b"
55-
// RESULT: ]
38+
// RESULT_SLOW-LABEL: key.results: [
39+
// RESULT_SLOW-DAG: key.name: "fooMethod()"
40+
// RESULT_SLOW-DAG: key.name: "self"
41+
// RESULT_SLOW-DAG: key.name: "x"
42+
// RESULT_SLOW-DAG: key.name: "y"
43+
// RESULT_SLOW: ]
44+
// RESULT_SLOW-NOT: key.reusingastcontext: 1
5645

57-
// TRACE_NORMAL-LABEL: key.notification: source.notification.compile-did-finish,
58-
// TRACE_NORMAL-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
59-
// TRACE_NORMAL-LABEL: key.notification: source.notification.compile-did-finish,
60-
// TRACE_NORMAL-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
46+
// RESULT_SLOW-LABEL: key.results: [
47+
// RESULT_SLOW-DAG: key.name: "barMethod()"
48+
// RESULT_SLOW-DAG: key.name: "self"
49+
// RESULT_SLOW-DAG: key.name: "a"
50+
// RESULT_SLOW-DAG: key.name: "b"
51+
// RESULT_SLOW: ]
52+
// RESULT_SLOW-NOT: key.reusingastcontext: 1
6153

62-
// TRACE_REUSEAST-LABEL: key.notification: source.notification.compile-did-finish,
63-
// TRACE_REUSEAST-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
64-
// TRACE_REUSEAST-LABEL: key.notification: source.notification.compile-did-finish,
65-
// TRACE_REUSEAST: key.description: "completion reusing previous ASTContext (benign diagnostic)"
54+
55+
// RESULT_FAST-LABEL: key.results: [
56+
// RESULT_FAST-DAG: key.name: "fooMethod()"
57+
// RESULT_FAST-DAG: key.name: "self"
58+
// RESULT_FAST-DAG: key.name: "x"
59+
// RESULT_FAST-DAG: key.name: "y"
60+
// RESULT_FAST: ]
61+
// RESULT_FAST-NOT: key.reusingastcontext: 1
62+
63+
// RESULT_FAST-LABEL: key.results: [
64+
// RESULT_FAST-DAG: key.name: "barMethod()"
65+
// RESULT_FAST-DAG: key.name: "self"
66+
// RESULT_FAST-DAG: key.name: "a"
67+
// RESULT_FAST-DAG: key.name: "b"
68+
// RESULT_FAST: ]
69+
// RESULT_FAST: key.reusingastcontext: 1

test/SourceKit/CodeComplete/complete_sequence_accessor.swift

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ enum S {
3838

3939
// Enabled.
4040
// RUN: %sourcekitd-test \
41-
// RUN: -req=track-compiles == \
4241
// RUN: -req=complete -pos=12:9 %s -- %s -parse-as-library == \
4342
// RUN: -req=complete -pos=15:15 %s -- %s -parse-as-library == \
4443
// RUN: -req=complete -pos=16:15 %s -- %s -parse-as-library == \
@@ -52,7 +51,6 @@ enum S {
5251
// RUN: -req=complete -pos=23:1 %s -- %s -parse-as-library == \
5352
// RUN: -req=complete -pos=16:1 %s -- %s -parse-as-library > %t.response
5453
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
55-
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response
5654

5755
// globalValImplicit
5856
// RESULT-LABEL: key.results: [
@@ -61,62 +59,80 @@ enum S {
6159
// RESULT-DAG: key.name: "a"
6260
// RESULT-DAG: key.name: "b"
6361
// RESULT: ]
62+
// RESULT-NOT: key.reusingastcontext: 1
63+
6464
// globalValGetSet(get)
6565
// RESULT-LABEL: key.results: [
6666
// RESULT-DAG: key.name: "fooMethod()"
6767
// RESULT-DAG: key.name: "self"
6868
// RESULT-DAG: key.name: "x"
6969
// RESULT-DAG: key.name: "y"
7070
// RESULT: ]
71+
// RESULT: key.reusingastcontext: 1
72+
7173
// globalValGetSet(set)
7274
// RESULT-LABEL: key.results: [
7375
// RESULT-DAG: key.name: "barMethod()"
7476
// RESULT-DAG: key.name: "self"
7577
// RESULT-DAG: key.name: "a"
7678
// RESULT-DAG: key.name: "b"
7779
// RESULT: ]
80+
// RESULT: key.reusingastcontext: 1
81+
7882
// propertyImplicit
7983
// RESULT-LABEL: key.results: [
8084
// RESULT-DAG: key.name: "fooMethod()"
8185
// RESULT-DAG: key.name: "self"
8286
// RESULT-DAG: key.name: "x"
8387
// RESULT-DAG: key.name: "y"
8488
// RESULT: ]
89+
// RESULT: key.reusingastcontext: 1
90+
8591
// propertyGetSet(get)
8692
// RESULT-LABEL: key.results: [
8793
// RESULT-DAG: key.name: "barMethod()"
8894
// RESULT-DAG: key.name: "self"
8995
// RESULT-DAG: key.name: "a"
9096
// RESULT-DAG: key.name: "b"
9197
// RESULT: ]
98+
// RESULT: key.reusingastcontext: 1
99+
92100
// propertyGetSet(set)
93101
// RESULT-LABEL: key.results: [
94102
// RESULT-DAG: key.name: "fooMethod()"
95103
// RESULT-DAG: key.name: "self"
96104
// RESULT-DAG: key.name: "x"
97105
// RESULT-DAG: key.name: "y"
98106
// RESULT: ]
107+
// RESULT: key.reusingastcontext: 1
108+
99109
// subscript(implicit getter)
100110
// RESULT-LABEL: key.results: [
101111
// RESULT-DAG: key.name: "fooMethod()"
102112
// RESULT-DAG: key.name: "self"
103113
// RESULT-DAG: key.name: "x"
104114
// RESULT-DAG: key.name: "y"
105115
// RESULT: ]
116+
// RESULT: key.reusingastcontext: 1
117+
106118
// subscript(get)
107119
// RESULT-LABEL: key.results: [
108120
// RESULT-DAG: key.name: "barMethod()"
109121
// RESULT-DAG: key.name: "self"
110122
// RESULT-DAG: key.name: "a"
111123
// RESULT-DAG: key.name: "b"
112124
// RESULT: ]
125+
// RESULT: key.reusingastcontext: 1
126+
113127
// subscript(set)
114128
// RESULT-LABEL: key.results: [
115129
// RESULT-DAG: key.name: "barMethod()"
116130
// RESULT-DAG: key.name: "self"
117131
// RESULT-DAG: key.name: "a"
118132
// RESULT-DAG: key.name: "b"
119133
// RESULT: ]
134+
// RESULT: key.reusingastcontext: 1
135+
120136
// accessor top (global var)
121137
// RESULT-LABEL: key.results: [
122138
// RESULT-DAG: key.description: "get"
@@ -125,6 +141,8 @@ enum S {
125141
// RESULT-DAG: key.description: "didSet"
126142
// RESULT-DAG: key.description: "Foo"
127143
// RESULT: ]
144+
// RESULT: key.reusingastcontext: 1
145+
128146
// accessor top (property)
129147
// RESULT-LABEL: key.results: [
130148
// RESULT-DAG: key.description: "get"
@@ -133,6 +151,8 @@ enum S {
133151
// RESULT-DAG: key.description: "didSet"
134152
// RESULT-DAG: key.description: "Foo"
135153
// RESULT: ]
154+
// RESULT: key.reusingastcontext: 1
155+
136156
// accessor second (global var)
137157
// RESULT-LABEL: key.results: [
138158
// RESULT-NOT: key.description: "Foo"
@@ -141,29 +161,4 @@ enum S {
141161
// RESULT-DAG: key.description: "willSet"
142162
// RESULT-DAG: key.description: "didSet"
143163
// RESULT: ]
144-
145-
146-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
147-
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
148-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
149-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
150-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
151-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
152-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
153-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
154-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
155-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
156-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
157-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
158-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
159-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
160-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
161-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
162-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
163-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
164-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
165-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
166-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
167-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
168-
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
169-
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
164+
// RESULT-NOT: key.reusingastcontext: 1

test/SourceKit/CodeComplete/complete_sequence_crossfile.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,28 @@ extension Bar {
2929

3030
// BEGIN dummy.swift
3131

32+
// NOTE: Test that switching editing file doesn't trigger fast-completion
33+
3234
// RUN: %empty-directory(%t)
3335
// RUN: %{python} %utils/split_file.py -o %t %s
3436

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

4242
// RESULT-LABEL: key.results: [
4343
// RESULT-DAG: key.name: "fooMethod()"
4444
// RESULT-DAG: key.name: "self"
4545
// RESULT-DAG: key.name: "x"
4646
// RESULT-DAG: key.name: "y"
4747
// RESULT: ]
48+
// RESULT-NOT: key.reusingastcontext: 1
49+
4850
// RESULT-LABEL: key.results: [
4951
// RESULT-DAG: key.name: "barMethod()"
5052
// RESULT-DAG: key.name: "self"
5153
// RESULT-DAG: key.name: "a"
5254
// RESULT-DAG: key.name: "b"
5355
// RESULT: ]
54-
55-
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
56+
// RESULT-NOT: key.reusingastcontext: 1

test/SourceKit/CodeComplete/complete_sequence_edit.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ func foo(arg: Foo) {
4444
// RUN: %{python} %utils/split_file.py -o %t %s
4545

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

5452
// RESULT-LABEL: key.results: [
5553
// RESULT-NOT: key.name: "z"
@@ -58,6 +56,7 @@ func foo(arg: Foo) {
5856
// RESULT-DAG: key.name: "x"
5957
// RESULT-DAG: key.name: "y"
6058
// RESULT: ]
59+
// RESULT-NOT: key.reusingastcontext: 1
6160

6261
// RESULT-LABEL: key.results: [
6362
// RESULT-NOT: key.name: "z"
@@ -66,6 +65,7 @@ func foo(arg: Foo) {
6665
// RESULT-DAG: key.name: "x"
6766
// RESULT-DAG: key.name: "y"
6867
// RESULT: ]
68+
// RESULT: key.reusingastcontext: 1
6969

7070
// RESULT-LABEL: key.results: [
7171
// RESULT-DAG: key.name: "fooMethod()"
@@ -74,16 +74,4 @@ func foo(arg: Foo) {
7474
// RESULT-DAG: key.name: "y"
7575
// RESULT-DAG: key.name: "z"
7676
// RESULT: ]
77-
78-
// TRACE: key.notification: source.notification.compile-did-finish,
79-
// TRACE-NEXT: key.diagnostics: [
80-
// TRACE-NEXT: ]
81-
82-
// TRACE: key.notification: source.notification.compile-did-finish,
83-
// TRACE-NEXT: key.diagnostics: [
84-
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"
85-
// TRACE: ]
86-
87-
// TRACE: key.notification: source.notification.compile-did-finish,
88-
// TRACE-NEXT: key.diagnostics: [
89-
// TRACE-NEXT: ]
77+
// RESULT-NOT: key.reusingastcontext: 1

0 commit comments

Comments
 (0)