[CodeCompletion] Refactor how code completion results are returned to support cancellation

This refactors a bunch of code-completion methods around `performOperation` to return their results via a callback only instead of the current mixed approach  of indicating failure via a return value, returning an error string as an inout parameter and success results via a callback. The new guarantee should be that the callback is always called exactly once on control flow graph.

Other than a support for passing the (currently unused) cancelled state through the different instance, there should be no functionality change.
This commit is contained in:
Alex Hoppen
2021-10-07 18:03:29 +02:00
parent c209f52b9c
commit 2fcb24e716
13 changed files with 691 additions and 184 deletions

View File

@@ -14,13 +14,15 @@
#define LLVM_SOURCEKIT_LIB_SWIFTLANG_SWIFTLANGSUPPORT_H
#include "CodeCompletion.h"
#include "SwiftInterfaceGenContext.h"
#include "SourceKit/Core/LangSupport.h"
#include "SourceKit/Support/Concurrency.h"
#include "SourceKit/Support/Statistic.h"
#include "SourceKit/Support/ThreadSafeRefCntPtr.h"
#include "SourceKit/Support/Tracing.h"
#include "SwiftInterfaceGenContext.h"
#include "swift/Basic/ThreadSafeRefCounted.h"
#include "swift/IDE/CancellableResult.h"
#include "swift/IDE/CompletionInstance.h"
#include "swift/IDE/Indenting.h"
#include "swift/IDE/Refactoring.h"
#include "swift/Index/IndexSymbol.h"
@@ -462,12 +464,13 @@ public:
/// Perform a completion like operation. It initializes a \c CompilerInstance,
/// the calls \p Callback with it. \p Callback must perform the second pass
/// using that instance.
bool performCompletionLikeOperation(
void performCompletionLikeOperation(
llvm::MemoryBuffer *UnresolvedInputFile, unsigned Offset,
ArrayRef<const char *> Args,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
std::string &Error,
llvm::function_ref<void(swift::CompilerInstance &, bool)> Callback);
llvm::function_ref<void(
swift::ide::CancellableResult<swift::ide::CompletionInstanceResult>)>
Callback);
//==========================================================================//
// LangSupport Interface