@@ -106,6 +106,7 @@ class CompletionInstance {
106106 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
107107 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
108108 DiagnosticConsumer *DiagC,
109+ std::shared_ptr<std::atomic<bool >> CancellationFlag,
109110 llvm::function_ref<void (CancellableResult<CompletionInstanceResult>)>
110111 Callback);
111112
@@ -119,6 +120,7 @@ class CompletionInstance {
119120 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
120121 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
121122 DiagnosticConsumer *DiagC,
123+ std::shared_ptr<std::atomic<bool >> CancellationFlag,
122124 llvm::function_ref<void (CancellableResult<CompletionInstanceResult>)>
123125 Callback);
124126
@@ -129,6 +131,14 @@ class CompletionInstance {
129131 // / In case of failure or cancellation, the callback receives the
130132 // / corresponding failed or cancelled result.
131133 // /
134+ // / If \p CancellationFlag is not \c nullptr, code completion can be cancelled
135+ // / by setting the flag to \c true.
136+ // / IMPORTANT: If \p CancellationFlag is not \c nullptr, then completion might
137+ // / be cancelled in the secon pass that's invoked inside \p Callback.
138+ // / Therefore, \p Callback MUST check whether completion was cancelled before
139+ // / interpreting the results, since invalid results may be returned in case
140+ // / of cancellation.
141+ // /
132142 // / NOTE: \p Args is only used for checking the equaity of the invocation.
133143 // / Since this function assumes that it is already normalized, exact the same
134144 // / arguments including their order is considered as the same invocation.
@@ -137,6 +147,7 @@ class CompletionInstance {
137147 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
138148 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
139149 DiagnosticConsumer *DiagC,
150+ std::shared_ptr<std::atomic<bool >> CancellationFlag,
140151 llvm::function_ref<void (CancellableResult<CompletionInstanceResult>)>
141152 Callback);
142153
@@ -155,13 +166,15 @@ class CompletionInstance {
155166 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
156167 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
157168 DiagnosticConsumer *DiagC, ide::CodeCompletionContext &CompletionContext,
169+ std::shared_ptr<std::atomic<bool >> CancellationFlag,
158170 llvm::function_ref<void (CancellableResult<CodeCompleteResult>)> Callback);
159171
160172 void typeContextInfo (
161173 swift::CompilerInvocation &Invocation, llvm::ArrayRef<const char *> Args,
162174 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
163175 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
164176 DiagnosticConsumer *DiagC,
177+ std::shared_ptr<std::atomic<bool >> CancellationFlag,
165178 llvm::function_ref<void (CancellableResult<TypeContextInfoResult>)>
166179 Callback);
167180
@@ -170,6 +183,7 @@ class CompletionInstance {
170183 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
171184 llvm::MemoryBuffer *completionBuffer, unsigned int Offset,
172185 DiagnosticConsumer *DiagC, ArrayRef<const char *> ExpectedTypeNames,
186+ std::shared_ptr<std::atomic<bool >> CancellationFlag,
173187 llvm::function_ref<void (CancellableResult<ConformingMethodListResults>)>
174188 Callback);
175189};
0 commit comments