@@ -26,7 +26,7 @@ ContextFreeCodeCompletionResult *
2626ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult (
2727 CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
2828 CodeCompletionString *CompletionString,
29- CodeCompletionOperatorKind KnownOperatorKind,
29+ CodeCompletionOperatorKind KnownOperatorKind, bool IsAsync,
3030 NullTerminatedStringRef BriefDocComment,
3131 CodeCompletionResultType ResultType,
3232 ContextFreeNotRecommendedReason NotRecommended,
@@ -43,7 +43,8 @@ ContextFreeCodeCompletionResult::createPatternOrBuiltInOperatorResult(
4343 }
4444 return new (Sink.getAllocator ()) ContextFreeCodeCompletionResult (
4545 Kind, /* AssociatedKind=*/ 0 , KnownOperatorKind,
46- /* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " , BriefDocComment,
46+ /* IsSystem=*/ false , IsAsync, CompletionString,
47+ /* ModuleName=*/ " " , BriefDocComment,
4748 /* AssociatedUSRs=*/ {}, ResultType, NotRecommended, DiagnosticSeverity,
4849 DiagnosticMessage,
4950 getCodeCompletionResultFilterName (CompletionString, Sink.getAllocator ()),
@@ -61,7 +62,8 @@ ContextFreeCodeCompletionResult::createKeywordResult(
6162 }
6263 return new (Sink.getAllocator ()) ContextFreeCodeCompletionResult (
6364 CodeCompletionResultKind::Keyword, static_cast <uint8_t >(Kind),
64- CodeCompletionOperatorKind::None, /* IsSystem=*/ false , CompletionString,
65+ CodeCompletionOperatorKind::None, /* IsSystem=*/ false , /* IsAsync=*/ false ,
66+ CompletionString,
6567 /* ModuleName=*/ " " , BriefDocComment,
6668 /* AssociatedUSRs=*/ {}, ResultType, ContextFreeNotRecommendedReason::None,
6769 CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " ,
@@ -80,7 +82,8 @@ ContextFreeCodeCompletionResult::createLiteralResult(
8082 return new (Sink.getAllocator ()) ContextFreeCodeCompletionResult (
8183 CodeCompletionResultKind::Literal, static_cast <uint8_t >(LiteralKind),
8284 CodeCompletionOperatorKind::None,
83- /* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " ,
85+ /* IsSystem=*/ false , /* IsAsync=*/ false , CompletionString,
86+ /* ModuleName=*/ " " ,
8487 /* BriefDocComment=*/ " " ,
8588 /* AssociatedUSRs=*/ {}, ResultType, ContextFreeNotRecommendedReason::None,
8689 CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " ,
@@ -95,7 +98,7 @@ getDeclNameForDiagnostics(const Decl *D, CodeCompletionResultSink &Sink) {
9598 llvm::raw_svector_ostream NameOS (Name);
9699 NameOS << " '" ;
97100 llvm::SmallString<64 > Scratch;
98- NameOS << VD->getName ().getString (Scratch );
101+ VD->getName ().printPretty (NameOS );
99102 NameOS << " '" ;
100103 return NullTerminatedStringRef (NameOS.str (), Sink.getAllocator ());
101104 } else {
@@ -106,8 +109,8 @@ getDeclNameForDiagnostics(const Decl *D, CodeCompletionResultSink &Sink) {
106109ContextFreeCodeCompletionResult *
107110ContextFreeCodeCompletionResult::createDeclResult (
108111 CodeCompletionResultSink &Sink, CodeCompletionString *CompletionString,
109- const Decl *AssociatedDecl, NullTerminatedStringRef ModuleName ,
110- NullTerminatedStringRef BriefDocComment,
112+ const Decl *AssociatedDecl, bool IsAsync ,
113+ NullTerminatedStringRef ModuleName, NullTerminatedStringRef BriefDocComment,
111114 ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
112115 CodeCompletionResultType ResultType,
113116 ContextFreeNotRecommendedReason NotRecommended,
@@ -121,8 +124,8 @@ ContextFreeCodeCompletionResult::createDeclResult(
121124 CodeCompletionResultKind::Declaration,
122125 static_cast <uint8_t >(getCodeCompletionDeclKind (AssociatedDecl)),
123126 CodeCompletionOperatorKind::None, getDeclIsSystem (AssociatedDecl),
124- CompletionString, ModuleName, BriefDocComment, AssociatedUSRs, ResultType ,
125- NotRecommended, DiagnosticSeverity, DiagnosticMessage,
127+ IsAsync, CompletionString, ModuleName, BriefDocComment, AssociatedUSRs,
128+ ResultType, NotRecommended, DiagnosticSeverity, DiagnosticMessage,
126129 getCodeCompletionResultFilterName (CompletionString, Sink.getAllocator ()),
127130 /* NameForDiagnostics=*/ getDeclNameForDiagnostics (AssociatedDecl, Sink));
128131}
@@ -288,14 +291,30 @@ bool ContextFreeCodeCompletionResult::getDeclIsSystem(const Decl *D) {
288291
289292// MARK: - CodeCompletionResult
290293
294+ static ContextualNotRecommendedReason
295+ getNotRecommenedReason (const ContextFreeCodeCompletionResult &ContextFree,
296+ bool CanCurrDeclContextHandleAsync,
297+ ContextualNotRecommendedReason ExplicitReason) {
298+ if (ExplicitReason != ContextualNotRecommendedReason::None) {
299+ return ExplicitReason;
300+ }
301+ if (ContextFree.isAsync () && !CanCurrDeclContextHandleAsync) {
302+ return ContextualNotRecommendedReason::InvalidAsyncContext;
303+ }
304+ return ContextualNotRecommendedReason::None;
305+ }
306+
291307CodeCompletionResult::CodeCompletionResult (
292308 const ContextFreeCodeCompletionResult &ContextFree,
293309 SemanticContextKind SemanticContext, CodeCompletionFlair Flair,
294310 uint8_t NumBytesToErase, const ExpectedTypeContext *TypeContext,
295311 const DeclContext *DC, const USRBasedTypeContext *USRTypeContext,
312+ bool CanCurrDeclContextHandleAsync,
296313 ContextualNotRecommendedReason NotRecommended)
297314 : ContextFree(ContextFree), SemanticContext(SemanticContext),
298- Flair(Flair.toRaw()), NotRecommended(NotRecommended),
315+ Flair(Flair.toRaw()),
316+ NotRecommended(getNotRecommenedReason(
317+ ContextFree, CanCurrDeclContextHandleAsync, NotRecommended)),
299318 NumBytesToErase(NumBytesToErase),
300319 TypeDistance(ContextFree.getResultType().calculateTypeRelation(
301320 TypeContext, DC, USRTypeContext)) {}
0 commit comments