@@ -306,7 +306,7 @@ class alignas(detail::CodeCompletionStringChunk) CodeCompletionString final :
306
306
return {getTrailingObjects<Chunk>(), NumChunks};
307
307
}
308
308
309
- StringRef getFirstTextChunk () const ;
309
+ StringRef getFirstTextChunk (bool includeLeadingPunctuation = false ) const ;
310
310
Optional<unsigned >
311
311
getFirstTextChunkIndex (bool includeLeadingPunctuation = false ) const ;
312
312
@@ -423,6 +423,52 @@ enum class CodeCompletionLiteralKind {
423
423
Tuple,
424
424
};
425
425
426
+ enum class CodeCompletionOperatorKind {
427
+ None,
428
+ Unknown,
429
+ Bang, // !
430
+ NotEq, // !=
431
+ NotEqEq, // !==
432
+ Modulo, // %
433
+ ModuloEq, // %=
434
+ Amp, // &
435
+ AmpAmp, // &&
436
+ AmpStar, // &*
437
+ AmpPlus, // &+
438
+ AmpMinus, // &-
439
+ AmpEq, // &=
440
+ LParen, // ( -- not really an operator, but treated as one in some cases.
441
+ Star, // *
442
+ StarEq, // *=
443
+ Plus, // +
444
+ PlusEq, // +=
445
+ Minus, // -
446
+ MinusEq, // -=
447
+ Dot, // .
448
+ DotDotDot, // ...
449
+ DotDotLess, // ..<
450
+ Slash, // /
451
+ SlashEq, // /=
452
+ Less, // <
453
+ LessLess, // <<
454
+ LessLessEq, // <<=
455
+ LessEq, // <=
456
+ Eq, // =
457
+ EqEq, // ==
458
+ EqEqEq, // ===
459
+ Greater, // >
460
+ GreaterEq, // >=
461
+ GreaterGreater, // >>
462
+ GreaterGreaterEq, // >>=
463
+ QuestionDot, // ?.
464
+ Caret, // ^
465
+ CaretEq, // ^=
466
+ Pipe, // |
467
+ PipeEq, // |=
468
+ PipePipe, // ||
469
+ TildeEq, // ~=
470
+ };
471
+
426
472
enum class CodeCompletionKeywordKind {
427
473
None,
428
474
#define KEYWORD (X ) kw_##X,
@@ -467,6 +513,7 @@ class CodeCompletionResult {
467
513
Keyword,
468
514
Pattern,
469
515
Literal,
516
+ BuiltinOperator,
470
517
};
471
518
472
519
// / Describes the relationship between the type of the completion results and
@@ -497,8 +544,9 @@ class CodeCompletionResult {
497
544
};
498
545
499
546
private:
500
- unsigned Kind : 2 ;
547
+ unsigned Kind : 3 ;
501
548
unsigned AssociatedKind : 8 ;
549
+ unsigned KnownOperatorKind : 6 ;
502
550
unsigned SemanticContext : 3 ;
503
551
unsigned NotRecommended : 1 ;
504
552
unsigned NotRecReason : 3 ;
@@ -520,20 +568,27 @@ class CodeCompletionResult {
520
568
unsigned TypeDistance : 3 ;
521
569
522
570
public:
523
- // / Constructs a \c Pattern or \c Keyword result.
571
+ // / Constructs a \c Pattern, \c Keyword or \c BuiltinOperator result.
524
572
// /
525
573
// / \note The caller must ensure \c CodeCompletionString outlives this result.
526
- CodeCompletionResult (ResultKind Kind,
527
- SemanticContextKind SemanticContext,
574
+ CodeCompletionResult (ResultKind Kind, SemanticContextKind SemanticContext,
528
575
unsigned NumBytesToErase,
529
576
CodeCompletionString *CompletionString,
530
- ExpectedTypeRelation TypeDistance = Unrelated)
531
- : Kind(Kind), SemanticContext(unsigned (SemanticContext)),
532
- NotRecommended (false ), NotRecReason(NotRecommendedReason::NoReason),
577
+ ExpectedTypeRelation TypeDistance = Unrelated,
578
+ CodeCompletionOperatorKind KnownOperatorKind =
579
+ CodeCompletionOperatorKind::None)
580
+ : Kind(Kind), KnownOperatorKind(unsigned (KnownOperatorKind)),
581
+ SemanticContext (unsigned (SemanticContext)), NotRecommended(false ),
582
+ NotRecReason(NotRecommendedReason::NoReason),
533
583
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
534
584
TypeDistance(TypeDistance) {
535
585
assert (Kind != Declaration && " use the other constructor" );
536
586
assert (CompletionString);
587
+ if (isOperator () && KnownOperatorKind == CodeCompletionOperatorKind::None)
588
+ this ->KnownOperatorKind =
589
+ (unsigned )getCodeCompletionOperatorKind (CompletionString);
590
+ assert (!isOperator () ||
591
+ getOperatorKind () != CodeCompletionOperatorKind::None);
537
592
AssociatedKind = 0 ;
538
593
}
539
594
@@ -545,8 +600,9 @@ class CodeCompletionResult {
545
600
unsigned NumBytesToErase,
546
601
CodeCompletionString *CompletionString,
547
602
ExpectedTypeRelation TypeDistance = Unrelated)
548
- : Kind(Keyword), SemanticContext(unsigned (SemanticContext)),
549
- NotRecommended(false ), NotRecReason(NotRecommendedReason::NoReason),
603
+ : Kind(Keyword), KnownOperatorKind(0 ),
604
+ SemanticContext(unsigned (SemanticContext)), NotRecommended(false ),
605
+ NotRecReason(NotRecommendedReason::NoReason),
550
606
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
551
607
TypeDistance(TypeDistance) {
552
608
assert (CompletionString);
@@ -561,8 +617,9 @@ class CodeCompletionResult {
561
617
unsigned NumBytesToErase,
562
618
CodeCompletionString *CompletionString,
563
619
ExpectedTypeRelation TypeDistance)
564
- : Kind(Literal), SemanticContext(unsigned (SemanticContext)),
565
- NotRecommended(false ), NotRecReason(NotRecommendedReason::NoReason),
620
+ : Kind(Literal), KnownOperatorKind(0 ),
621
+ SemanticContext(unsigned (SemanticContext)), NotRecommended(false ),
622
+ NotRecReason(NotRecommendedReason::NoReason),
566
623
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
567
624
TypeDistance(TypeDistance) {
568
625
AssociatedKind = static_cast <unsigned >(LiteralKind);
@@ -584,16 +641,21 @@ class CodeCompletionResult {
584
641
ArrayRef<StringRef> AssociatedUSRs,
585
642
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
586
643
enum ExpectedTypeRelation TypeDistance)
587
- : Kind(ResultKind::Declaration),
644
+ : Kind(ResultKind::Declaration), KnownOperatorKind( 0 ),
588
645
SemanticContext(unsigned (SemanticContext)),
589
646
NotRecommended(NotRecommended), NotRecReason(NotRecReason),
590
- NumBytesToErase(NumBytesToErase),
591
- CompletionString(CompletionString ), ModuleName(ModuleName ),
592
- BriefDocComment(BriefDocComment ), AssociatedUSRs(AssociatedUSRs ),
593
- DocWords(DocWords), TypeDistance(TypeDistance) {
647
+ NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
648
+ ModuleName(ModuleName ), BriefDocComment(BriefDocComment ),
649
+ AssociatedUSRs(AssociatedUSRs ), DocWords(DocWords ),
650
+ TypeDistance(TypeDistance) {
594
651
assert (AssociatedDecl && " should have a decl" );
595
652
AssociatedKind = unsigned (getCodeCompletionDeclKind (AssociatedDecl));
596
653
assert (CompletionString);
654
+ if (isOperator ())
655
+ KnownOperatorKind =
656
+ (unsigned )getCodeCompletionOperatorKind (CompletionString);
657
+ assert (!isOperator () ||
658
+ getOperatorKind () != CodeCompletionOperatorKind::None);
597
659
}
598
660
599
661
// FIXME:
@@ -605,17 +667,20 @@ class CodeCompletionResult {
605
667
CodeCompletionResult::NotRecommendedReason NotRecReason,
606
668
StringRef BriefDocComment,
607
669
ArrayRef<StringRef> AssociatedUSRs,
608
- ArrayRef<std::pair<StringRef, StringRef>> DocWords)
670
+ ArrayRef<std::pair<StringRef, StringRef>> DocWords,
671
+ CodeCompletionOperatorKind KnownOperatorKind)
609
672
: Kind(ResultKind::Declaration),
673
+ KnownOperatorKind(unsigned (KnownOperatorKind)),
610
674
SemanticContext(unsigned (SemanticContext)),
611
675
NotRecommended(NotRecommended), NotRecReason(NotRecReason),
612
- NumBytesToErase(NumBytesToErase),
613
- CompletionString(CompletionString), ModuleName(ModuleName),
614
- BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
615
- DocWords(DocWords) {
676
+ NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
677
+ ModuleName(ModuleName), BriefDocComment(BriefDocComment),
678
+ AssociatedUSRs(AssociatedUSRs), DocWords(DocWords) {
616
679
AssociatedKind = static_cast <unsigned >(DeclKind);
617
680
assert (CompletionString);
618
681
TypeDistance = ExpectedTypeRelation::Unrelated;
682
+ assert (!isOperator () ||
683
+ getOperatorKind () != CodeCompletionOperatorKind::None);
619
684
}
620
685
621
686
ResultKind getKind () const { return static_cast <ResultKind>(Kind); }
@@ -637,7 +702,7 @@ class CodeCompletionResult {
637
702
638
703
bool isOperator () const {
639
704
if (getKind () != Declaration)
640
- return false ;
705
+ return getKind () == BuiltinOperator ;
641
706
switch (getAssociatedDeclKind ()) {
642
707
case CodeCompletionDeclKind::PrefixOperatorFunction:
643
708
case CodeCompletionDeclKind::PostfixOperatorFunction:
@@ -648,6 +713,11 @@ class CodeCompletionResult {
648
713
}
649
714
}
650
715
716
+ CodeCompletionOperatorKind getOperatorKind () const {
717
+ assert (isOperator ());
718
+ return static_cast <CodeCompletionOperatorKind>(KnownOperatorKind);
719
+ }
720
+
651
721
ExpectedTypeRelation getExpectedTypeRelation () const {
652
722
return static_cast <ExpectedTypeRelation>(TypeDistance);
653
723
}
@@ -691,6 +761,10 @@ class CodeCompletionResult {
691
761
void dump () const ;
692
762
693
763
static CodeCompletionDeclKind getCodeCompletionDeclKind (const Decl *D);
764
+ static CodeCompletionOperatorKind
765
+ getCodeCompletionOperatorKind (StringRef name);
766
+ static CodeCompletionOperatorKind
767
+ getCodeCompletionOperatorKind (CodeCompletionString *str);
694
768
};
695
769
696
770
struct CodeCompletionResultSink {
0 commit comments