mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user