@@ -329,6 +329,7 @@ class ContextFreeCodeCompletionResult {
329
329
static_assert (int (CodeCompletionOperatorKind::MAX_VALUE) < 1 << 6 , " " );
330
330
331
331
bool IsSystem : 1 ;
332
+ bool IsAsync : 1 ;
332
333
CodeCompletionString *CompletionString;
333
334
NullTerminatedStringRef ModuleName;
334
335
NullTerminatedStringRef BriefDocComment;
@@ -344,6 +345,10 @@ class ContextFreeCodeCompletionResult {
344
345
NullTerminatedStringRef DiagnosticMessage;
345
346
NullTerminatedStringRef FilterName;
346
347
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
+
347
352
public:
348
353
// / Memberwise initializer. \p AssociatedKInd is opaque and will be
349
354
// / interpreted based on \p Kind. If \p KnownOperatorKind is \c None and the
@@ -355,7 +360,7 @@ class ContextFreeCodeCompletionResult {
355
360
// / \c CodeCompletionResultSink as the result itself.
356
361
ContextFreeCodeCompletionResult (
357
362
CodeCompletionResultKind Kind, uint8_t AssociatedKind,
358
- CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem,
363
+ CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem, bool IsAsync,
359
364
CodeCompletionString *CompletionString,
360
365
NullTerminatedStringRef ModuleName,
361
366
NullTerminatedStringRef BriefDocComment,
@@ -364,13 +369,15 @@ class ContextFreeCodeCompletionResult {
364
369
ContextFreeNotRecommendedReason NotRecommended,
365
370
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
366
371
NullTerminatedStringRef DiagnosticMessage,
367
- NullTerminatedStringRef FilterName)
372
+ NullTerminatedStringRef FilterName,
373
+ NullTerminatedStringRef NameForDiagnostics)
368
374
: 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) {
374
381
this ->AssociatedKind .Opaque = AssociatedKind;
375
382
assert ((NotRecommended == ContextFreeNotRecommendedReason::None) ==
376
383
(DiagnosticSeverity == CodeCompletionDiagnosticSeverity::None) &&
@@ -396,7 +403,7 @@ class ContextFreeCodeCompletionResult {
396
403
static ContextFreeCodeCompletionResult *createPatternOrBuiltInOperatorResult (
397
404
CodeCompletionResultSink &Sink, CodeCompletionResultKind Kind,
398
405
CodeCompletionString *CompletionString,
399
- CodeCompletionOperatorKind KnownOperatorKind,
406
+ CodeCompletionOperatorKind KnownOperatorKind, bool IsAsync,
400
407
NullTerminatedStringRef BriefDocComment,
401
408
CodeCompletionResultType ResultType,
402
409
ContextFreeNotRecommendedReason NotRecommended,
@@ -431,15 +438,17 @@ class ContextFreeCodeCompletionResult {
431
438
// / \note The caller must ensure that the \p CompletionString and all
432
439
// / \c StringRefs outlive this result, typically by storing them in the same
433
440
// / \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);
443
452
444
453
CodeCompletionResultKind getKind () const { return Kind; }
445
454
@@ -469,6 +478,8 @@ class ContextFreeCodeCompletionResult {
469
478
470
479
bool isSystem () const { return IsSystem; };
471
480
481
+ bool isAsync () const { return IsAsync; };
482
+
472
483
CodeCompletionString *getCompletionString () const { return CompletionString; }
473
484
474
485
NullTerminatedStringRef getModuleName () const { return ModuleName; }
@@ -494,6 +505,10 @@ class ContextFreeCodeCompletionResult {
494
505
495
506
NullTerminatedStringRef getFilterName () const { return FilterName; }
496
507
508
+ NullTerminatedStringRef getNameForDiagnostics () const {
509
+ return NameForDiagnostics;
510
+ }
511
+
497
512
bool isOperator () const {
498
513
if (getKind () == CodeCompletionResultKind::Declaration) {
499
514
switch (getAssociatedDeclKind ()) {
@@ -531,11 +546,6 @@ class CodeCompletionResult {
531
546
ContextualNotRecommendedReason NotRecommended : 4 ;
532
547
static_assert (int (ContextualNotRecommendedReason::MAX_VALUE) < 1 << 4 , " " );
533
548
534
- CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3 ;
535
- static_assert (int (CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3 , " " );
536
-
537
- NullTerminatedStringRef DiagnosticMessage;
538
-
539
549
// / The number of bytes to the left of the code completion point that
540
550
// / should be erased first if this completion string is inserted in the
541
551
// / editor buffer.
@@ -556,14 +566,10 @@ class CodeCompletionResult {
556
566
SemanticContextKind SemanticContext,
557
567
CodeCompletionFlair Flair, uint8_t NumBytesToErase,
558
568
CodeCompletionResultTypeRelation TypeDistance,
559
- ContextualNotRecommendedReason NotRecommended,
560
- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
561
- NullTerminatedStringRef DiagnosticMessage)
569
+ ContextualNotRecommendedReason NotRecommended)
562
570
: ContextFree(ContextFree), SemanticContext(SemanticContext),
563
571
Flair (Flair.toRaw()), NotRecommended(NotRecommended),
564
- DiagnosticSeverity(DiagnosticSeverity),
565
- DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
566
- TypeDistance(TypeDistance) {}
572
+ NumBytesToErase(NumBytesToErase), TypeDistance(TypeDistance) {}
567
573
568
574
public:
569
575
// / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
@@ -581,9 +587,8 @@ class CodeCompletionResult {
581
587
const ExpectedTypeContext *TypeContext,
582
588
const DeclContext *DC,
583
589
const USRBasedTypeContext *USRTypeContext,
584
- ContextualNotRecommendedReason NotRecommended,
585
- CodeCompletionDiagnosticSeverity DiagnosticSeverity,
586
- NullTerminatedStringRef DiagnosticMessage);
590
+ bool CanCurrDeclContextHandleAsync,
591
+ ContextualNotRecommendedReason NotRecommended);
587
592
588
593
const ContextFreeCodeCompletionResult &getContextFreeResult () const {
589
594
return ContextFree;
@@ -702,37 +707,23 @@ class CodeCompletionResult {
702
707
return getContextFreeResult ().getAssociatedUSRs ();
703
708
}
704
709
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 {
732
722
if (NotRecommended != ContextualNotRecommendedReason::None) {
733
- return DiagnosticMessage ;
723
+ return getContextualDiagnosticSeverityAndMessage (Scratch, Ctx) ;
734
724
} else {
735
- return getContextFreeResult ().getDiagnosticMessage ();
725
+ return std::make_pair (getContextFreeResult ().getDiagnosticSeverity (),
726
+ getContextFreeResult ().getDiagnosticMessage ());
736
727
}
737
728
}
738
729
0 commit comments