@@ -341,6 +341,10 @@ class ContextFreeCodeCompletionResult {
341341 NullTerminatedStringRef DiagnosticMessage;
342342 NullTerminatedStringRef FilterName;
343343
344+ // / If the result represents a \c ValueDecl the name by which this decl should
345+ // / be refered to in diagnostics.
346+ NullTerminatedStringRef NameForDiagnostics;
347+
344348public:
345349 // / Memberwise initializer. \p AssociatedKInd is opaque and will be
346350 // / interpreted based on \p Kind. If \p KnownOperatorKind is \c None and the
@@ -361,13 +365,15 @@ class ContextFreeCodeCompletionResult {
361365 ContextFreeNotRecommendedReason NotRecommended,
362366 CodeCompletionDiagnosticSeverity DiagnosticSeverity,
363367 NullTerminatedStringRef DiagnosticMessage,
364- NullTerminatedStringRef FilterName)
368+ NullTerminatedStringRef FilterName,
369+ NullTerminatedStringRef NameForDiagnostics)
365370 : Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
366371 CompletionString (CompletionString), ModuleName(ModuleName),
367372 BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
368373 ResultType(ResultType), NotRecommended(NotRecommended),
369374 DiagnosticSeverity(DiagnosticSeverity),
370- DiagnosticMessage(DiagnosticMessage), FilterName(FilterName) {
375+ DiagnosticMessage(DiagnosticMessage), FilterName(FilterName),
376+ NameForDiagnostics(NameForDiagnostics) {
371377 this ->AssociatedKind .Opaque = AssociatedKind;
372378 assert ((NotRecommended == ContextFreeNotRecommendedReason::None) ==
373379 (DiagnosticSeverity == CodeCompletionDiagnosticSeverity::None) &&
@@ -491,6 +497,10 @@ class ContextFreeCodeCompletionResult {
491497
492498 NullTerminatedStringRef getFilterName () const { return FilterName; }
493499
500+ NullTerminatedStringRef getNameForDiagnostics () const {
501+ return NameForDiagnostics;
502+ }
503+
494504 bool isOperator () const {
495505 if (getKind () == CodeCompletionResultKind::Declaration) {
496506 switch (getAssociatedDeclKind ()) {
@@ -528,11 +538,6 @@ class CodeCompletionResult {
528538 ContextualNotRecommendedReason NotRecommended : 4 ;
529539 static_assert (int (ContextualNotRecommendedReason::MAX_VALUE) < 1 << 4 , " " );
530540
531- CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3 ;
532- static_assert (int (CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3 , " " );
533-
534- NullTerminatedStringRef DiagnosticMessage;
535-
536541 // / The number of bytes to the left of the code completion point that
537542 // / should be erased first if this completion string is inserted in the
538543 // / editor buffer.
@@ -553,14 +558,10 @@ class CodeCompletionResult {
553558 SemanticContextKind SemanticContext,
554559 CodeCompletionFlair Flair, uint8_t NumBytesToErase,
555560 CodeCompletionResultTypeRelation TypeDistance,
556- ContextualNotRecommendedReason NotRecommended,
557- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
558- NullTerminatedStringRef DiagnosticMessage)
561+ ContextualNotRecommendedReason NotRecommended)
559562 : ContextFree(ContextFree), SemanticContext(SemanticContext),
560563 Flair (Flair.toRaw()), NotRecommended(NotRecommended),
561- DiagnosticSeverity(DiagnosticSeverity),
562- DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
563- TypeDistance(TypeDistance) {}
564+ NumBytesToErase(NumBytesToErase), TypeDistance(TypeDistance) {}
564565
565566public:
566567 // / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
@@ -578,9 +579,7 @@ class CodeCompletionResult {
578579 const ExpectedTypeContext *TypeContext,
579580 const DeclContext *DC,
580581 const USRBasedTypeContext *USRTypeContext,
581- ContextualNotRecommendedReason NotRecommended,
582- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
583- NullTerminatedStringRef DiagnosticMessage);
582+ ContextualNotRecommendedReason NotRecommended);
584583
585584 const ContextFreeCodeCompletionResult &getContextFreeResult () const {
586585 return ContextFree;
@@ -699,37 +698,23 @@ class CodeCompletionResult {
699698 return getContextFreeResult ().getAssociatedUSRs ();
700699 }
701700
702- // / Get the contextual diagnostic severity. This disregards context-free
703- // / diagnostics.
704- CodeCompletionDiagnosticSeverity getContextualDiagnosticSeverity () const {
705- return DiagnosticSeverity;
706- }
707-
708- // / Get the contextual diagnostic message. This disregards context-free
709- // / diagnostics.
710- NullTerminatedStringRef getContextualDiagnosticMessage () const {
711- return DiagnosticMessage;
712- }
713-
714- // / Return the contextual diagnostic severity if there was a contextual
715- // / diagnostic. If there is no contextual diagnostic, return the context-free
716- // / diagnostic severity.
717- CodeCompletionDiagnosticSeverity getDiagnosticSeverity () const {
718- if (NotRecommended != ContextualNotRecommendedReason::None) {
719- return DiagnosticSeverity;
720- } else {
721- return getContextFreeResult ().getDiagnosticSeverity ();
722- }
723- }
724-
725- // / Return the contextual diagnostic message if there was a contextual
726- // / diagnostic. If there is no contextual diagnostic, return the context-free
727- // / diagnostic message.
728- NullTerminatedStringRef getDiagnosticMessage () const {
701+ // / Get the contextual diagnostic severity and message. This disregards
702+ // / context-free diagnostics.
703+ std::pair<CodeCompletionDiagnosticSeverity, NullTerminatedStringRef>
704+ getContextualDiagnosticSeverityAndMessage (SmallVectorImpl<char > &Scratch,
705+ const ASTContext &Ctx) const ;
706+
707+ // / Return the contextual diagnostic severity and message if there was a
708+ // / contextual diagnostic. If there is no contextual diagnostic, return the
709+ // / context-free diagnostic severity and message.
710+ std::pair<CodeCompletionDiagnosticSeverity, NullTerminatedStringRef>
711+ getDiagnosticSeverityAndMessage (SmallVectorImpl<char > &Scratch,
712+ const ASTContext &Ctx) const {
729713 if (NotRecommended != ContextualNotRecommendedReason::None) {
730- return DiagnosticMessage ;
714+ return getContextualDiagnosticSeverityAndMessage (Scratch, Ctx) ;
731715 } else {
732- return getContextFreeResult ().getDiagnosticMessage ();
716+ return std::make_pair (getContextFreeResult ().getDiagnosticSeverity (),
717+ getContextFreeResult ().getDiagnosticMessage ());
733718 }
734719 }
735720
0 commit comments