16
16
#include " swift/AST/Identifier.h"
17
17
#include " swift/Basic/Debug.h"
18
18
#include " swift/Basic/LLVM.h"
19
+ #include " swift/Basic/OptionSet.h"
19
20
#include " llvm/ADT/ArrayRef.h"
20
21
#include " llvm/ADT/StringMap.h"
21
22
#include " llvm/ADT/StringRef.h"
@@ -375,33 +376,6 @@ enum class SemanticContextKind {
375
376
// / Used in cases when the concept of semantic context is not applicable.
376
377
None,
377
378
378
- // / This is a highly-likely expression-context-specific completion
379
- // / result. This description is intentionally vague: this is a catch-all
380
- // / category for all heuristics for highly-likely results.
381
- // /
382
- // / For example, the name of an overridden superclass member inside a nominal
383
- // / member function has ExpressionSpecific context:
384
- // / \code
385
- // / class Base {
386
- // / init() {}
387
- // / init(a: Int) {}
388
- // / func foo() {}
389
- // / func bar() {}
390
- // / }
391
- // / class Derived {
392
- // / init() {
393
- // / super. // init() -- ExpressionSpecific
394
- // / // init(a: Int) -- Super
395
- // / }
396
- // /
397
- // / func foo() {
398
- // / super. // foo() -- ExpressionSpecific
399
- // / // bar() -- Super
400
- // / }
401
- // / }
402
- // / \endcode
403
- ExpressionSpecific,
404
-
405
379
// / A declaration from the same function.
406
380
Local,
407
381
@@ -434,6 +408,26 @@ enum class SemanticContextKind {
434
408
OtherModule,
435
409
};
436
410
411
+ enum class CodeCompletionFlairBit : uint8_t {
412
+ // / **Deprecated**. Old style catch-all prioritization.
413
+ ExpressionSpecific = 1 << 0 ,
414
+
415
+ // / E.g. override func foo() { super.foo() ...
416
+ SuperChain = 1 << 1 ,
417
+
418
+ // / Argument label and type. i.e. 'label: <#Ty#>'.
419
+ ArgumentLabels = 1 << 2 ,
420
+
421
+ // / E.g. decl introducer or modifiers ('enum', 'protocol', 'public', etc.) at
422
+ // / top-level.
423
+ CommonKeywordAtCurrentPosition = 1 << 3 ,
424
+
425
+ // / E.g. type decl introducer ('enum', 'class', etc.) in a function body.
426
+ RareKeywordAtCurrentPosition = 1 << 4 ,
427
+ };
428
+
429
+ using CodeCompletionFlair = OptionSet<CodeCompletionFlairBit>;
430
+
437
431
// / The declaration kind of a code completion result, if it is a declaration.
438
432
enum class CodeCompletionDeclKind {
439
433
Module,
@@ -615,7 +609,7 @@ class CodeCompletionResult {
615
609
unsigned AssociatedKind : 8 ;
616
610
unsigned KnownOperatorKind : 6 ;
617
611
unsigned SemanticContext : 3 ;
618
- unsigned IsArgumentLabels : 1 ;
612
+ unsigned Flair: 8 ;
619
613
unsigned NotRecommended : 4 ;
620
614
unsigned IsSystem : 1 ;
621
615
@@ -640,15 +634,14 @@ class CodeCompletionResult {
640
634
// /
641
635
// / \note The caller must ensure \c CodeCompletionString outlives this result.
642
636
CodeCompletionResult (ResultKind Kind, SemanticContextKind SemanticContext,
643
- bool IsArgumentLabels , unsigned NumBytesToErase,
637
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
644
638
CodeCompletionString *CompletionString,
645
639
ExpectedTypeRelation TypeDistance,
646
640
CodeCompletionOperatorKind KnownOperatorKind =
647
641
CodeCompletionOperatorKind::None,
648
642
StringRef BriefDocComment = StringRef())
649
643
: Kind(Kind), KnownOperatorKind(unsigned (KnownOperatorKind)),
650
- SemanticContext (unsigned (SemanticContext)),
651
- IsArgumentLabels(unsigned (IsArgumentLabels)),
644
+ SemanticContext (unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
652
645
NotRecommended(unsigned (NotRecommendedReason::None)),
653
646
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
654
647
BriefDocComment(BriefDocComment), TypeDistance(TypeDistance) {
@@ -668,13 +661,13 @@ class CodeCompletionResult {
668
661
// / \note The caller must ensure \c CodeCompletionString outlives this result.
669
662
CodeCompletionResult (CodeCompletionKeywordKind Kind,
670
663
SemanticContextKind SemanticContext,
671
- bool IsArgumentLabels, unsigned NumBytesToErase,
664
+ CodeCompletionFlair Flair,
665
+ unsigned NumBytesToErase,
672
666
CodeCompletionString *CompletionString,
673
667
ExpectedTypeRelation TypeDistance,
674
668
StringRef BriefDocComment = StringRef())
675
669
: Kind(Keyword), KnownOperatorKind(0 ),
676
- SemanticContext(unsigned (SemanticContext)),
677
- IsArgumentLabels(unsigned (IsArgumentLabels)),
670
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
678
671
NotRecommended(unsigned (NotRecommendedReason::None)),
679
672
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
680
673
BriefDocComment(BriefDocComment), TypeDistance(TypeDistance) {
@@ -688,12 +681,11 @@ class CodeCompletionResult {
688
681
// / \note The caller must ensure \c CodeCompletionString outlives this result.
689
682
CodeCompletionResult (CodeCompletionLiteralKind LiteralKind,
690
683
SemanticContextKind SemanticContext,
691
- bool IsArgumentLabels , unsigned NumBytesToErase,
684
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
692
685
CodeCompletionString *CompletionString,
693
686
ExpectedTypeRelation TypeDistance)
694
687
: Kind(Literal), KnownOperatorKind(0 ),
695
- SemanticContext(unsigned (SemanticContext)),
696
- IsArgumentLabels(unsigned (IsArgumentLabels)),
688
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
697
689
NotRecommended(unsigned (NotRecommendedReason::None)),
698
690
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
699
691
TypeDistance(TypeDistance) {
@@ -708,7 +700,7 @@ class CodeCompletionResult {
708
700
// / arguments outlive this result, typically by storing them in the same
709
701
// / \c CodeCompletionResultSink as the result itself.
710
702
CodeCompletionResult (SemanticContextKind SemanticContext,
711
- bool IsArgumentLabels , unsigned NumBytesToErase,
703
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
712
704
CodeCompletionString *CompletionString,
713
705
const Decl *AssociatedDecl, StringRef ModuleName,
714
706
CodeCompletionResult::NotRecommendedReason NotRecReason,
@@ -717,8 +709,7 @@ class CodeCompletionResult {
717
709
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
718
710
enum ExpectedTypeRelation TypeDistance)
719
711
: Kind(ResultKind::Declaration), KnownOperatorKind(0 ),
720
- SemanticContext(unsigned (SemanticContext)),
721
- IsArgumentLabels(unsigned (IsArgumentLabels)),
712
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
722
713
NotRecommended(unsigned (NotRecReason)),
723
714
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
724
715
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
@@ -737,7 +728,7 @@ class CodeCompletionResult {
737
728
738
729
// Used by deserialization.
739
730
CodeCompletionResult (SemanticContextKind SemanticContext,
740
- bool IsArgumentLabels , unsigned NumBytesToErase,
731
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
741
732
CodeCompletionString *CompletionString,
742
733
CodeCompletionDeclKind DeclKind, bool IsSystem,
743
734
StringRef ModuleName,
@@ -749,8 +740,7 @@ class CodeCompletionResult {
749
740
CodeCompletionOperatorKind KnownOperatorKind)
750
741
: Kind(ResultKind::Declaration),
751
742
KnownOperatorKind(unsigned (KnownOperatorKind)),
752
- SemanticContext(unsigned (SemanticContext)),
753
- IsArgumentLabels(unsigned (IsArgumentLabels)),
743
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
754
744
NotRecommended(unsigned (NotRecReason)), IsSystem(IsSystem),
755
745
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
756
746
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
@@ -813,8 +803,8 @@ class CodeCompletionResult {
813
803
return static_cast <SemanticContextKind>(SemanticContext);
814
804
}
815
805
816
- bool isArgumentLabels () const {
817
- return static_cast <bool >(IsArgumentLabels );
806
+ CodeCompletionFlair getFlair () const {
807
+ return static_cast <CodeCompletionFlair>(Flair );
818
808
}
819
809
820
810
bool isNotRecommended () const {
0 commit comments