[CodeCompletion] Don't recommend functions with async alternatives in async contexts

When an function has an async alternative, that should be preferred when we are completing in an async context. Thus, the sync method should be marked as not recommended if the current context can handle async methods.

rdar://88354910
This commit is contained in:
Alex Hoppen
2022-08-01 14:24:53 +02:00
parent 5c29bd2968
commit daec367b46
10 changed files with 69 additions and 30 deletions

View File

@@ -104,7 +104,7 @@ CodeCompletionCache::~CodeCompletionCache() {}
/// This should be incremented any time we commit a change to the format of the
/// cached results. This isn't expected to change very often.
static constexpr uint32_t onDiskCompletionCacheVersion =
9; // Store whether a decl is async
10; // Store if decl has an async alternative
/// Deserializes CodeCompletionResults from \p in and stores them in \p V.
/// \see writeCacheModule.
@@ -236,6 +236,7 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
static_cast<CodeCompletionDiagnosticSeverity>(*cursor++);
auto isSystem = static_cast<bool>(*cursor++);
auto isAsync = static_cast<bool>(*cursor++);
auto hasAsyncAlternative = static_cast<bool>(*cursor++);
auto chunkIndex = read32le(cursor);
auto moduleIndex = read32le(cursor);
auto briefDocIndex = read32le(cursor);
@@ -265,8 +266,9 @@ static bool readCachedModule(llvm::MemoryBuffer *in,
ContextFreeCodeCompletionResult *result =
new (*V.Allocator) ContextFreeCodeCompletionResult(
kind, associatedKind, opKind, isSystem, isAsync, string, moduleName,
briefDocComment, makeArrayRef(assocUSRs).copy(*V.Allocator),
kind, associatedKind, opKind, isSystem, isAsync,
hasAsyncAlternative, string, moduleName, briefDocComment,
makeArrayRef(assocUSRs).copy(*V.Allocator),
CodeCompletionResultType(resultTypes), notRecommended, diagSeverity,
diagMessage, filterName, nameForDiagnostics);
@@ -425,6 +427,7 @@ static void writeCachedModule(llvm::raw_ostream &out,
LE.write(static_cast<uint8_t>(R->getDiagnosticSeverity()));
LE.write(static_cast<uint8_t>(R->isSystem()));
LE.write(static_cast<uint8_t>(R->isAsync()));
LE.write(static_cast<uint8_t>(R->hasAsyncAlternative()));
LE.write(
static_cast<uint32_t>(addCompletionString(R->getCompletionString())));
LE.write(addString(R->getModuleName())); // index into strings