[SourceKit] Support cancellation of code completion like requests

Essentially, just wire up cancellation tokens and cancellation flags for `CompletionInstance` and make sure to return `CancellableResult::cancelled()` when cancellation is detected.

rdar://83391488
This commit is contained in:
Alex Hoppen
2021-12-02 13:05:03 +01:00
parent d482ee392e
commit 177ab6e8e7
11 changed files with 282 additions and 148 deletions

View File

@@ -999,6 +999,7 @@ void SwiftLangSupport::performWithParamsToCompletionLikeOperation(
llvm::MemoryBuffer *UnresolvedInputFile, unsigned Offset,
ArrayRef<const char *> Args,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
SourceKitCancellationToken CancellationToken,
llvm::function_ref<void(CancellableResult<CompletionLikeOperationParams>)>
PerformOperation) {
assert(FileSystem);
@@ -1058,8 +1059,13 @@ void SwiftLangSupport::performWithParamsToCompletionLikeOperation(
// Pin completion instance.
auto CompletionInst = getCompletionInstance();
CompletionLikeOperationParams Params = {Invocation, newBuffer.get(),
&CIDiags};
auto CancellationFlag = std::make_shared<std::atomic<bool>>(false);
ReqTracker->setCancellationHandler(CancellationToken, [CancellationFlag] {
CancellationFlag->store(true, std::memory_order_relaxed);
});
CompletionLikeOperationParams Params = {Invocation, newBuffer.get(), &CIDiags,
CancellationFlag};
PerformOperation(
CancellableResult<CompletionLikeOperationParams>::success(Params));
}