@@ -329,6 +329,7 @@ class ContextFreeCodeCompletionResult {
329329 static_assert (int (CodeCompletionOperatorKind::MAX_VALUE) < 1 << 6 , " " );
330330
331331 bool IsSystem : 1 ;
332+ bool IsAsync : 1 ;
332333 CodeCompletionString *CompletionString;
333334 NullTerminatedStringRef ModuleName;
334335 NullTerminatedStringRef BriefDocComment;
@@ -344,6 +345,10 @@ class ContextFreeCodeCompletionResult {
344345 NullTerminatedStringRef DiagnosticMessage;
345346 NullTerminatedStringRef FilterName;
346347
348+ // / If the result represents a \c ValueDecl the name by which this decl should
349+ // / be refered to in diagnostics.
350+ NullTerminatedStringRef NameForDiagnostics;
351+
347352public:
348353 // / Memberwise initializer. \p AssociatedKInd is opaque and will be
349354 // / interpreted based on \p Kind. If \p KnownOperatorKind is \c None and the
@@ -355,7 +360,7 @@ class ContextFreeCodeCompletionResult {
355360 // / \c CodeCompletionResultSink as the result itself.
356361 ContextFreeCodeCompletionResult (
357362 CodeCompletionResultKind Kind, uint8_t AssociatedKind,
358- CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem,
363+ CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem, bool IsAsync,
359364 CodeCompletionString *CompletionString,
360365 NullTerminatedStringRef ModuleName,
361366 NullTerminatedStringRef BriefDocComment,
@@ -364,13 +369,15 @@ class ContextFreeCodeCompletionResult {
364369 ContextFreeNotRecommendedReason NotRecommended,
365370 CodeCompletionDiagnosticSeverity DiagnosticSeverity,
366371 NullTerminatedStringRef DiagnosticMessage,
367- NullTerminatedStringRef FilterName)
372+ NullTerminatedStringRef FilterName,
373+ NullTerminatedStringRef NameForDiagnostics)
368374 : Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
369- CompletionString (CompletionString), ModuleName(ModuleName),
370- BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
371- ResultType(ResultType), NotRecommended(NotRecommended),
372- DiagnosticSeverity(DiagnosticSeverity),
373- DiagnosticMessage(DiagnosticMessage), FilterName(FilterName) {
375+ IsAsync (IsAsync), CompletionString(CompletionString),
376+ ModuleName(ModuleName), BriefDocComment(BriefDocComment),
377+ AssociatedUSRs(AssociatedUSRs), ResultType(ResultType),
378+ NotRecommended(NotRecommended), DiagnosticSeverity(DiagnosticSeverity),
379+ DiagnosticMessage(DiagnosticMessage), FilterName(FilterName),
380+ NameForDiagnostics(NameForDiagnostics) {
374381 this ->AssociatedKind .Opaque = AssociatedKind;
375382 assert ((NotRecommended == ContextFreeNotRecommendedReason::None) ==
376383 (DiagnosticSeverity == CodeCompletionDiagnosticSeverity::None) &&
@@ -396,7 +403,7 @@ class ContextFreeCodeCompletionResult {
396403 static ContextFreeCodeCompletionResult *createPatternOrBuiltInOperatorResult (
397404 CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
398405 CodeCompletionString *CompletionString,
399- CodeCompletionOperatorKind KnownOperatorKind,
406+ CodeCompletionOperatorKind KnownOperatorKind, bool IsAsync,
400407 NullTerminatedStringRef BriefDocComment,
401408 CodeCompletionResultType ResultType,
402409 ContextFreeNotRecommendedReason NotRecommended,
@@ -431,15 +438,17 @@ class ContextFreeCodeCompletionResult {
431438 // / \note The caller must ensure that the \p CompletionString and all
432439 // / \c StringRefs outlive this result, typically by storing them in the same
433440 // / \c CodeCompletionResultSink as the result itself.
434- static ContextFreeCodeCompletionResult *createDeclResult (
435- CodeCompletionResultSink &Sink, CodeCompletionString *CompletionString,
436- const Decl *AssociatedDecl, NullTerminatedStringRef ModuleName,
437- NullTerminatedStringRef BriefDocComment,
438- ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
439- CodeCompletionResultType ResultType,
440- ContextFreeNotRecommendedReason NotRecommended,
441- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
442- NullTerminatedStringRef DiagnosticMessage);
441+ static ContextFreeCodeCompletionResult *
442+ createDeclResult (CodeCompletionResultSink &Sink,
443+ CodeCompletionString *CompletionString,
444+ const Decl *AssociatedDecl, bool IsAsync,
445+ NullTerminatedStringRef ModuleName,
446+ NullTerminatedStringRef BriefDocComment,
447+ ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
448+ CodeCompletionResultType ResultType,
449+ ContextFreeNotRecommendedReason NotRecommended,
450+ CodeCompletionDiagnosticSeverity DiagnosticSeverity,
451+ NullTerminatedStringRef DiagnosticMessage);
443452
444453 CodeCompletionResultKind getKind () const { return Kind; }
445454
@@ -469,6 +478,8 @@ class ContextFreeCodeCompletionResult {
469478
470479 bool isSystem () const { return IsSystem; };
471480
481+ bool isAsync () const { return IsAsync; };
482+
472483 CodeCompletionString *getCompletionString () const { return CompletionString; }
473484
474485 NullTerminatedStringRef getModuleName () const { return ModuleName; }
@@ -494,6 +505,10 @@ class ContextFreeCodeCompletionResult {
494505
495506 NullTerminatedStringRef getFilterName () const { return FilterName; }
496507
508+ NullTerminatedStringRef getNameForDiagnostics () const {
509+ return NameForDiagnostics;
510+ }
511+
497512 bool isOperator () const {
498513 if (getKind () == CodeCompletionResultKind::Declaration) {
499514 switch (getAssociatedDeclKind ()) {
@@ -531,11 +546,6 @@ class CodeCompletionResult {
531546 ContextualNotRecommendedReason NotRecommended : 4 ;
532547 static_assert (int (ContextualNotRecommendedReason::MAX_VALUE) < 1 << 4 , " " );
533548
534- CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3 ;
535- static_assert (int (CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3 , " " );
536-
537- NullTerminatedStringRef DiagnosticMessage;
538-
539549 // / The number of bytes to the left of the code completion point that
540550 // / should be erased first if this completion string is inserted in the
541551 // / editor buffer.
@@ -556,14 +566,10 @@ class CodeCompletionResult {
556566 SemanticContextKind SemanticContext,
557567 CodeCompletionFlair Flair, uint8_t NumBytesToErase,
558568 CodeCompletionResultTypeRelation TypeDistance,
559- ContextualNotRecommendedReason NotRecommended,
560- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
561- NullTerminatedStringRef DiagnosticMessage)
569+ ContextualNotRecommendedReason NotRecommended)
562570 : ContextFree(ContextFree), SemanticContext(SemanticContext),
563571 Flair (Flair.toRaw()), NotRecommended(NotRecommended),
564- DiagnosticSeverity(DiagnosticSeverity),
565- DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
566- TypeDistance(TypeDistance) {}
572+ NumBytesToErase(NumBytesToErase), TypeDistance(TypeDistance) {}
567573
568574public:
569575 // / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
@@ -581,9 +587,8 @@ class CodeCompletionResult {
581587 const ExpectedTypeContext *TypeContext,
582588 const DeclContext *DC,
583589 const USRBasedTypeContext *USRTypeContext,
584- ContextualNotRecommendedReason NotRecommended,
585- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
586- NullTerminatedStringRef DiagnosticMessage);
590+ bool CanCurrDeclContextHandleAsync,
591+ ContextualNotRecommendedReason NotRecommended);
587592
588593 const ContextFreeCodeCompletionResult &getContextFreeResult () const {
589594 return ContextFree;
@@ -702,37 +707,23 @@ class CodeCompletionResult {
702707 return getContextFreeResult ().getAssociatedUSRs ();
703708 }
704709
705- // / Get the contextual diagnostic severity. This disregards context-free
706- // / diagnostics.
707- CodeCompletionDiagnosticSeverity getContextualDiagnosticSeverity () const {
708- return DiagnosticSeverity;
709- }
710-
711- // / Get the contextual diagnostic message. This disregards context-free
712- // / diagnostics.
713- NullTerminatedStringRef getContextualDiagnosticMessage () const {
714- return DiagnosticMessage;
715- }
716-
717- // / Return the contextual diagnostic severity if there was a contextual
718- // / diagnostic. If there is no contextual diagnostic, return the context-free
719- // / diagnostic severity.
720- CodeCompletionDiagnosticSeverity getDiagnosticSeverity () const {
721- if (NotRecommended != ContextualNotRecommendedReason::None) {
722- return DiagnosticSeverity;
723- } else {
724- return getContextFreeResult ().getDiagnosticSeverity ();
725- }
726- }
727-
728- // / Return the contextual diagnostic message if there was a contextual
729- // / diagnostic. If there is no contextual diagnostic, return the context-free
730- // / diagnostic message.
731- NullTerminatedStringRef getDiagnosticMessage () const {
710+ // / Get the contextual diagnostic severity and message. This disregards
711+ // / context-free diagnostics.
712+ std::pair<CodeCompletionDiagnosticSeverity, NullTerminatedStringRef>
713+ getContextualDiagnosticSeverityAndMessage (SmallVectorImpl<char > &Scratch,
714+ const ASTContext &Ctx) const ;
715+
716+ // / Return the contextual diagnostic severity and message if there was a
717+ // / contextual diagnostic. If there is no contextual diagnostic, return the
718+ // / context-free diagnostic severity and message.
719+ std::pair<CodeCompletionDiagnosticSeverity, NullTerminatedStringRef>
720+ getDiagnosticSeverityAndMessage (SmallVectorImpl<char > &Scratch,
721+ const ASTContext &Ctx) const {
732722 if (NotRecommended != ContextualNotRecommendedReason::None) {
733- return DiagnosticMessage ;
723+ return getContextualDiagnosticSeverityAndMessage (Scratch, Ctx) ;
734724 } else {
735- return getContextFreeResult ().getDiagnosticMessage ();
725+ return std::make_pair (getContextFreeResult ().getDiagnosticSeverity (),
726+ getContextFreeResult ().getDiagnosticMessage ());
736727 }
737728 }
738729
0 commit comments