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"
@@ -32,12 +33,14 @@ class Decl;
32
33
class DeclContext ;
33
34
class FrontendOptions ;
34
35
class ModuleDecl ;
36
+ class SourceFile ;
35
37
36
38
namespace ide {
37
39
38
40
class CodeCompletionCache ;
39
41
class CodeCompletionContext ;
40
42
class CodeCompletionResultBuilder ;
43
+ struct CodeCompletionResultSink ;
41
44
struct RequestedCachedModule ;
42
45
43
46
// / A routine to remove code completion tokens from code completion
@@ -375,33 +378,6 @@ enum class SemanticContextKind {
375
378
// / Used in cases when the concept of semantic context is not applicable.
376
379
None,
377
380
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
381
// / A declaration from the same function.
406
382
Local,
407
383
@@ -434,6 +410,33 @@ enum class SemanticContextKind {
434
410
OtherModule,
435
411
};
436
412
413
+ enum class CodeCompletionFlairBit : uint8_t {
414
+ // / **Deprecated**. Old style catch-all prioritization.
415
+ ExpressionSpecific = 1 << 0 ,
416
+
417
+ // / E.g. override func foo() { super.foo() ...
418
+ SuperChain = 1 << 1 ,
419
+
420
+ // / Argument label and type. i.e. 'label: <#Ty#>'.
421
+ ArgumentLabels = 1 << 2 ,
422
+
423
+ // / E.g. decl introducer or modifiers ('enum', 'protocol', 'public', etc.) at
424
+ // / top-level.
425
+ CommonKeywordAtCurrentPosition = 1 << 3 ,
426
+
427
+ // / E.g. type decl introducer ('enum', 'class', etc.) in a function body.
428
+ RareKeywordAtCurrentPosition = 1 << 4 ,
429
+
430
+ // / E.g. protocol names at an expression position.
431
+ RareTypeAtCurrentPosition = 1 << 5 ,
432
+
433
+ // / E.g. referencing a type, function, etc… at top level position in a non
434
+ // / script/main.swift file
435
+ ExpressionAtNonScriptOrMainFileScope = 1 << 6 ,
436
+ };
437
+
438
+ using CodeCompletionFlair = OptionSet<CodeCompletionFlairBit>;
439
+
437
440
// / The declaration kind of a code completion result, if it is a declaration.
438
441
enum class CodeCompletionDeclKind {
439
442
Module,
@@ -615,7 +618,7 @@ class CodeCompletionResult {
615
618
unsigned AssociatedKind : 8 ;
616
619
unsigned KnownOperatorKind : 6 ;
617
620
unsigned SemanticContext : 3 ;
618
- unsigned IsArgumentLabels : 1 ;
621
+ unsigned Flair: 8 ;
619
622
unsigned NotRecommended : 4 ;
620
623
unsigned IsSystem : 1 ;
621
624
@@ -640,15 +643,14 @@ class CodeCompletionResult {
640
643
// /
641
644
// / \note The caller must ensure \c CodeCompletionString outlives this result.
642
645
CodeCompletionResult (ResultKind Kind, SemanticContextKind SemanticContext,
643
- bool IsArgumentLabels , unsigned NumBytesToErase,
646
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
644
647
CodeCompletionString *CompletionString,
645
648
ExpectedTypeRelation TypeDistance,
646
649
CodeCompletionOperatorKind KnownOperatorKind =
647
650
CodeCompletionOperatorKind::None,
648
651
StringRef BriefDocComment = StringRef())
649
652
: Kind(Kind), KnownOperatorKind(unsigned (KnownOperatorKind)),
650
- SemanticContext (unsigned (SemanticContext)),
651
- IsArgumentLabels(unsigned (IsArgumentLabels)),
653
+ SemanticContext (unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
652
654
NotRecommended(unsigned (NotRecommendedReason::None)),
653
655
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
654
656
BriefDocComment(BriefDocComment), TypeDistance(TypeDistance) {
@@ -668,13 +670,13 @@ class CodeCompletionResult {
668
670
// / \note The caller must ensure \c CodeCompletionString outlives this result.
669
671
CodeCompletionResult (CodeCompletionKeywordKind Kind,
670
672
SemanticContextKind SemanticContext,
671
- bool IsArgumentLabels, unsigned NumBytesToErase,
673
+ CodeCompletionFlair Flair,
674
+ unsigned NumBytesToErase,
672
675
CodeCompletionString *CompletionString,
673
676
ExpectedTypeRelation TypeDistance,
674
677
StringRef BriefDocComment = StringRef())
675
678
: Kind(Keyword), KnownOperatorKind(0 ),
676
- SemanticContext(unsigned (SemanticContext)),
677
- IsArgumentLabels(unsigned (IsArgumentLabels)),
679
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
678
680
NotRecommended(unsigned (NotRecommendedReason::None)),
679
681
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
680
682
BriefDocComment(BriefDocComment), TypeDistance(TypeDistance) {
@@ -688,12 +690,11 @@ class CodeCompletionResult {
688
690
// / \note The caller must ensure \c CodeCompletionString outlives this result.
689
691
CodeCompletionResult (CodeCompletionLiteralKind LiteralKind,
690
692
SemanticContextKind SemanticContext,
691
- bool IsArgumentLabels , unsigned NumBytesToErase,
693
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
692
694
CodeCompletionString *CompletionString,
693
695
ExpectedTypeRelation TypeDistance)
694
696
: Kind(Literal), KnownOperatorKind(0 ),
695
- SemanticContext(unsigned (SemanticContext)),
696
- IsArgumentLabels(unsigned (IsArgumentLabels)),
697
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
697
698
NotRecommended(unsigned (NotRecommendedReason::None)),
698
699
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
699
700
TypeDistance(TypeDistance) {
@@ -708,7 +709,7 @@ class CodeCompletionResult {
708
709
// / arguments outlive this result, typically by storing them in the same
709
710
// / \c CodeCompletionResultSink as the result itself.
710
711
CodeCompletionResult (SemanticContextKind SemanticContext,
711
- bool IsArgumentLabels , unsigned NumBytesToErase,
712
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
712
713
CodeCompletionString *CompletionString,
713
714
const Decl *AssociatedDecl, StringRef ModuleName,
714
715
CodeCompletionResult::NotRecommendedReason NotRecReason,
@@ -717,8 +718,7 @@ class CodeCompletionResult {
717
718
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
718
719
enum ExpectedTypeRelation TypeDistance)
719
720
: Kind(ResultKind::Declaration), KnownOperatorKind(0 ),
720
- SemanticContext(unsigned (SemanticContext)),
721
- IsArgumentLabels(unsigned (IsArgumentLabels)),
721
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
722
722
NotRecommended(unsigned (NotRecReason)),
723
723
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
724
724
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
@@ -737,7 +737,7 @@ class CodeCompletionResult {
737
737
738
738
// Used by deserialization.
739
739
CodeCompletionResult (SemanticContextKind SemanticContext,
740
- bool IsArgumentLabels , unsigned NumBytesToErase,
740
+ CodeCompletionFlair Flair , unsigned NumBytesToErase,
741
741
CodeCompletionString *CompletionString,
742
742
CodeCompletionDeclKind DeclKind, bool IsSystem,
743
743
StringRef ModuleName,
@@ -749,8 +749,7 @@ class CodeCompletionResult {
749
749
CodeCompletionOperatorKind KnownOperatorKind)
750
750
: Kind(ResultKind::Declaration),
751
751
KnownOperatorKind(unsigned (KnownOperatorKind)),
752
- SemanticContext(unsigned (SemanticContext)),
753
- IsArgumentLabels(unsigned (IsArgumentLabels)),
752
+ SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
754
753
NotRecommended(unsigned (NotRecReason)), IsSystem(IsSystem),
755
754
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
756
755
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
@@ -762,6 +761,12 @@ class CodeCompletionResult {
762
761
getOperatorKind () != CodeCompletionOperatorKind::None);
763
762
}
764
763
764
+ // / Copy this result to \p Sink with \p newFlair . Note that this does NOT
765
+ // / copy the value of \c CompletionString , \c AssociatedUSRs etc. it only
766
+ // / copies the pointers to them.
767
+ CodeCompletionResult *withFlair (CodeCompletionFlair newFlair,
768
+ CodeCompletionResultSink &Sink);
769
+
765
770
ResultKind getKind () const { return static_cast <ResultKind>(Kind); }
766
771
767
772
CodeCompletionDeclKind getAssociatedDeclKind () const {
@@ -813,8 +818,13 @@ class CodeCompletionResult {
813
818
return static_cast <SemanticContextKind>(SemanticContext);
814
819
}
815
820
816
- bool isArgumentLabels () const {
817
- return static_cast <bool >(IsArgumentLabels);
821
+ CodeCompletionFlair getFlair () const {
822
+ return static_cast <CodeCompletionFlair>(Flair);
823
+ }
824
+
825
+ // / Modify "flair" of this result *in place*.
826
+ void setFlair (CodeCompletionFlair flair) {
827
+ Flair = unsigned (flair.toRaw ());
818
828
}
819
829
820
830
bool isNotRecommended () const {
@@ -971,7 +981,7 @@ class CodeCompletionConsumer {
971
981
virtual void
972
982
handleResultsAndModules (CodeCompletionContext &context,
973
983
ArrayRef<RequestedCachedModule> requestedModules,
974
- DeclContext *DCForModules ) = 0 ;
984
+ DeclContext *DC ) = 0 ;
975
985
};
976
986
977
987
// / A simplified code completion consumer interface that clients can use to get
@@ -1024,14 +1034,15 @@ void lookupCodeCompletionResultsFromModule(CodeCompletionResultSink &targetSink,
1024
1034
const ModuleDecl *module ,
1025
1035
ArrayRef<std::string> accessPath,
1026
1036
bool needLeadingDot,
1027
- const DeclContext *currDeclContext );
1037
+ const SourceFile *SF );
1028
1038
1029
1039
// / Copy code completion results from \p sourceSink to \p targetSink, possibly
1030
- // / restricting by \p onlyTypes.
1031
- void copyCodeCompletionResults (CodeCompletionResultSink &targetSink,
1032
- CodeCompletionResultSink &sourceSink,
1033
- bool onlyTypes,
1034
- bool onlyPrecedenceGroups);
1040
+ // / restricting by \p onlyTypes. Returns copied results in \p targetSink.
1041
+ MutableArrayRef<CodeCompletionResult *>
1042
+ copyCodeCompletionResults (CodeCompletionResultSink &targetSink,
1043
+ CodeCompletionResultSink &sourceSink,
1044
+ bool onlyTypes,
1045
+ bool onlyPrecedenceGroups);
1035
1046
1036
1047
} // end namespace ide
1037
1048
} // end namespace swift
0 commit comments