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