[SourceKit] Allow passing cancel_on_subsequent_request: 0 for all requests that use a OncePerASTToken

We need this option for `collectVariableType` (aka inlay type hints) but since I’m at it, I’m adding an option to disable the implicit request cancellation for all requests that have it since we don’t want it in LSP at all.

Prerequisite to fixing https://github.com/swiftlang/sourcekit-lsp/issues/2021 / rdar://145871554, need to adopt this option in SourceKit-LSP.
This commit is contained in:
Alex Hoppen
2025-05-14 18:42:19 +02:00
parent 810fbcee9c
commit 5bd9e439ee
6 changed files with 56 additions and 14 deletions

View File

@@ -2776,7 +2776,8 @@ static RefactoringKind getIDERefactoringKind(SemanticRefactoringInfo Info) {
void SwiftLangSupport::semanticRefactoring(
StringRef PrimaryFilePath, SemanticRefactoringInfo Info,
ArrayRef<const char *> Args, SourceKitCancellationToken CancellationToken,
ArrayRef<const char *> Args, bool CancelOnSubsequentRequest,
SourceKitCancellationToken CancellationToken,
CategorizedEditsReceiver Receiver) {
std::string Error;
SwiftInvocationRef Invok =
@@ -2834,7 +2835,8 @@ void SwiftLangSupport::semanticRefactoring(
/// FIXME: When request cancellation is implemented and Xcode adopts it,
/// don't use 'OncePerASTToken'.
static const char OncePerASTToken = 0;
getASTManager()->processASTAsync(Invok, std::move(Consumer), &OncePerASTToken,
const void *Once = CancelOnSubsequentRequest ? &OncePerASTToken : nullptr;
getASTManager()->processASTAsync(Invok, std::move(Consumer), Once,
CancellationToken,
llvm::vfs::getRealFileSystem());
}
@@ -2918,6 +2920,7 @@ void SwiftLangSupport::collectVariableTypes(
StringRef PrimaryFilePath, StringRef InputBufferName,
ArrayRef<const char *> Args, std::optional<unsigned> Offset,
std::optional<unsigned> Length, bool FullyQualified,
bool CancelOnSubsequentRequest,
SourceKitCancellationToken CancellationToken,
std::function<void(const RequestResult<VariableTypesInFile> &)> Receiver) {
std::string Error;
@@ -2997,7 +3000,8 @@ void SwiftLangSupport::collectVariableTypes(
/// FIXME: When request cancellation is implemented and Xcode adopts it,
/// don't use 'OncePerASTToken'.
static const char OncePerASTToken = 0;
getASTManager()->processASTAsync(Invok, std::move(Collector),
&OncePerASTToken, CancellationToken,
const void *Once = CancelOnSubsequentRequest ? &OncePerASTToken : nullptr;
getASTManager()->processASTAsync(Invok, std::move(Collector), Once,
CancellationToken,
llvm::vfs::getRealFileSystem());
}