@@ -341,6 +341,10 @@ class ContextFreeCodeCompletionResult {
341
341
NullTerminatedStringRef DiagnosticMessage;
342
342
NullTerminatedStringRef FilterName;
343
343
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
+
344
348
public:
345
349
// / Memberwise initializer. \p AssociatedKInd is opaque and will be
346
350
// / interpreted based on \p Kind. If \p KnownOperatorKind is \c None and the
@@ -361,13 +365,15 @@ class ContextFreeCodeCompletionResult {
361
365
ContextFreeNotRecommendedReason NotRecommended,
362
366
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
363
367
NullTerminatedStringRef DiagnosticMessage,
364
- NullTerminatedStringRef FilterName)
368
+ NullTerminatedStringRef FilterName,
369
+ NullTerminatedStringRef NameForDiagnostics)
365
370
: Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
366
371
CompletionString (CompletionString), ModuleName(ModuleName),
367
372
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
368
373
ResultType(ResultType), NotRecommended(NotRecommended),
369
374
DiagnosticSeverity(DiagnosticSeverity),
370
- DiagnosticMessage(DiagnosticMessage), FilterName(FilterName) {
375
+ DiagnosticMessage(DiagnosticMessage), FilterName(FilterName),
376
+ NameForDiagnostics(NameForDiagnostics) {
371
377
this ->AssociatedKind .Opaque = AssociatedKind;
372
378
assert ((NotRecommended == ContextFreeNotRecommendedReason::None) ==
373
379
(DiagnosticSeverity == CodeCompletionDiagnosticSeverity::None) &&
@@ -491,6 +497,10 @@ class ContextFreeCodeCompletionResult {
491
497
492
498
NullTerminatedStringRef getFilterName () const { return FilterName; }
493
499
500
+ NullTerminatedStringRef getNameForDiagnostics () const {
501
+ return NameForDiagnostics;
502
+ }
503
+
494
504
bool isOperator () const {
495
505
if (getKind () == CodeCompletionResultKind::Declaration) {
496
506
switch (getAssociatedDeclKind ()) {
@@ -528,11 +538,6 @@ class CodeCompletionResult {
528
538
ContextualNotRecommendedReason NotRecommended : 4 ;
529
539
static_assert (int (ContextualNotRecommendedReason::MAX_VALUE) < 1 << 4 , " " );
530
540
531
- CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3 ;
532
- static_assert (int (CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3 , " " );
533
-
534
- NullTerminatedStringRef DiagnosticMessage;
535
-
536
541
// / The number of bytes to the left of the code completion point that
537
542
// / should be erased first if this completion string is inserted in the
538
543
// / editor buffer.
@@ -553,14 +558,10 @@ class CodeCompletionResult {
553
558
SemanticContextKind SemanticContext,
554
559
CodeCompletionFlair Flair, uint8_t NumBytesToErase,
555
560
CodeCompletionResultTypeRelation TypeDistance,
556
- ContextualNotRecommendedReason NotRecommended,
557
- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
558
- NullTerminatedStringRef DiagnosticMessage)
561
+ ContextualNotRecommendedReason NotRecommended)
559
562
: ContextFree(ContextFree), SemanticContext(SemanticContext),
560
563
Flair (Flair.toRaw()), NotRecommended(NotRecommended),
561
- DiagnosticSeverity(DiagnosticSeverity),
562
- DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
563
- TypeDistance(TypeDistance) {}
564
+ NumBytesToErase(NumBytesToErase), TypeDistance(TypeDistance) {}
564
565
565
566
public:
566
567
// / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
@@ -578,9 +579,7 @@ class CodeCompletionResult {
578
579
const ExpectedTypeContext *TypeContext,
579
580
const DeclContext *DC,
580
581
const USRBasedTypeContext *USRTypeContext,
581
- ContextualNotRecommendedReason NotRecommended,
582
- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
583
- NullTerminatedStringRef DiagnosticMessage);
582
+ ContextualNotRecommendedReason NotRecommended);
584
583
585
584
const ContextFreeCodeCompletionResult &getContextFreeResult () const {
586
585
return ContextFree;
@@ -699,37 +698,23 @@ class CodeCompletionResult {
699
698
return getContextFreeResult ().getAssociatedUSRs ();
700
699
}
701
700
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 {
729
713
if (NotRecommended != ContextualNotRecommendedReason::None) {
730
- return DiagnosticMessage ;
714
+ return getContextualDiagnosticSeverityAndMessage (Scratch, Ctx) ;
731
715
} else {
732
- return getContextFreeResult ().getDiagnosticMessage ();
716
+ return std::make_pair (getContextFreeResult ().getDiagnosticSeverity (),
717
+ getContextFreeResult ().getDiagnosticMessage ());
733
718
}
734
719
}
735
720
0 commit comments