[CodeCompletion] Compute InvalidAsyncContext warning when making a completion result contextual

Store whether a result is async in the `ContextFreeCodeCompletionResult` and determine whether an async method is used in a sync context when promoting the context free result to a contextual result.

rdar://78317170
This commit is contained in:
Alex Hoppen
2022-07-21 14:27:19 +02:00
parent 9fc850abed
commit dec32674ef
15 changed files with 135 additions and 77 deletions

View File

@@ -134,15 +134,16 @@ bool SourceKit::CodeCompletion::addCustomCompletions(
auto *contextFreeResult =
ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult(
sink.swiftSink, CodeCompletionResultKind::Pattern, completionString,
CodeCompletionOperatorKind::None, /*BriefDocComment=*/"",
CodeCompletionResultType::unknown(),
CodeCompletionOperatorKind::None, /*IsAsync=*/false,
/*BriefDocComment=*/"", CodeCompletionResultType::unknown(),
ContextFreeNotRecommendedReason::None,
CodeCompletionDiagnosticSeverity::None, /*DiagnosticMessage=*/"");
auto *swiftResult = new (sink.allocator) CodeCompletion::SwiftResult(
*contextFreeResult, SemanticContextKind::Local,
CodeCompletionFlairBit::ExpressionSpecific,
/*NumBytesToErase=*/0, /*TypeContext=*/nullptr, /*DC=*/nullptr,
/*USRTypeContext=*/nullptr, ContextualNotRecommendedReason::None);
/*USRTypeContext=*/nullptr, /*CanCurrDeclContextHandleAsync=*/false,
ContextualNotRecommendedReason::None);
CompletionBuilder builder(sink, *swiftResult);
builder.setCustomKind(customCompletion.Kind);
@@ -1165,8 +1166,8 @@ Completion *CompletionBuilder::finish() {
new (sink.allocator) ContextFreeCodeCompletionResult(
contextFreeBase.getKind(),
contextFreeBase.getOpaqueAssociatedKind(), opKind,
contextFreeBase.isSystem(), newCompletionString,
contextFreeBase.getModuleName(),
contextFreeBase.isSystem(), contextFreeBase.isAsync(),
newCompletionString, contextFreeBase.getModuleName(),
contextFreeBase.getBriefDocComment(),
contextFreeBase.getAssociatedUSRs(),
contextFreeBase.getResultType(),