13
13
#ifndef SWIFT_IDE_CODECOMPLETION_H
14
14
#define SWIFT_IDE_CODECOMPLETION_H
15
15
16
+ #include " CodeCompletionResultType.h"
16
17
#include " swift/AST/Identifier.h"
17
18
#include " swift/Basic/Debug.h"
18
19
#include " swift/Basic/LLVM.h"
@@ -701,31 +702,6 @@ enum class CodeCompletionResultKind : uint8_t {
701
702
MAX_VALUE = BuiltinOperator
702
703
};
703
704
704
- // / Describes the relationship between the type of the completion results and
705
- // / the expected type at the code completion position.
706
- enum class CodeCompletionResultTypeRelation : uint8_t {
707
- // / The result does not have a type (e.g. keyword).
708
- NotApplicable,
709
-
710
- // / The type relation have not been calculated.
711
- Unknown,
712
-
713
- // / The relationship of the result's type to the expected type is not
714
- // / invalid, not convertible, and not identical.
715
- Unrelated,
716
-
717
- // / The result's type is invalid at the expected position.
718
- Invalid,
719
-
720
- // / The result's type is convertible to the type of the expected.
721
- Convertible,
722
-
723
- // / The result's type is identical to the type of the expected.
724
- Identical,
725
-
726
- MAX_VALUE = Identical
727
- };
728
-
729
705
// / The parts of a \c CodeCompletionResult that are not dependent on the context
730
706
// / it appears in and can thus be cached.
731
707
class ContextFreeCodeCompletionResult {
@@ -749,6 +725,7 @@ class ContextFreeCodeCompletionResult {
749
725
StringRef ModuleName;
750
726
StringRef BriefDocComment;
751
727
ArrayRef<StringRef> AssociatedUSRs;
728
+ CodeCompletionResultType ResultType;
752
729
753
730
ContextFreeNotRecommendedReason NotRecommended : 3 ;
754
731
static_assert (int (ContextFreeNotRecommendedReason::MAX_VALUE) < 1 << 3 , " " );
@@ -772,13 +749,15 @@ class ContextFreeCodeCompletionResult {
772
749
CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem,
773
750
CodeCompletionString *CompletionString, StringRef ModuleName,
774
751
StringRef BriefDocComment, ArrayRef<StringRef> AssociatedUSRs,
752
+ CodeCompletionResultType ResultType,
775
753
ContextFreeNotRecommendedReason NotRecommended,
776
754
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
777
755
StringRef DiagnosticMessage)
778
756
: Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
779
757
CompletionString (CompletionString), ModuleName(ModuleName),
780
758
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
781
- NotRecommended(NotRecommended), DiagnosticSeverity(DiagnosticSeverity),
759
+ ResultType(ResultType), NotRecommended(NotRecommended),
760
+ DiagnosticSeverity(DiagnosticSeverity),
782
761
DiagnosticMessage(DiagnosticMessage) {
783
762
this ->AssociatedKind .Opaque = AssociatedKind;
784
763
assert ((NotRecommended == ContextFreeNotRecommendedReason::None) ==
@@ -805,13 +784,14 @@ class ContextFreeCodeCompletionResult {
805
784
ContextFreeCodeCompletionResult (
806
785
CodeCompletionResultKind Kind, CodeCompletionString *CompletionString,
807
786
CodeCompletionOperatorKind KnownOperatorKind, StringRef BriefDocComment,
787
+ CodeCompletionResultType ResultType,
808
788
ContextFreeNotRecommendedReason NotRecommended,
809
789
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
810
790
StringRef DiagnosticMessage)
811
791
: ContextFreeCodeCompletionResult(
812
792
Kind, /* AssociatedKind=*/ 0 , KnownOperatorKind,
813
793
/* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " ,
814
- BriefDocComment, /* AssociatedUSRs=*/ {}, NotRecommended,
794
+ BriefDocComment, /* AssociatedUSRs=*/ {}, ResultType, NotRecommended,
815
795
DiagnosticSeverity, DiagnosticMessage) {}
816
796
817
797
// / Constructs a \c Keyword result.
@@ -821,12 +801,14 @@ class ContextFreeCodeCompletionResult {
821
801
// / same \c CodeCompletionResultSink as the result itself.
822
802
ContextFreeCodeCompletionResult (CodeCompletionKeywordKind Kind,
823
803
CodeCompletionString *CompletionString,
824
- StringRef BriefDocComment)
804
+ StringRef BriefDocComment,
805
+ CodeCompletionResultType ResultType)
825
806
: ContextFreeCodeCompletionResult(
826
807
CodeCompletionResultKind::Keyword, static_cast <uint8_t >(Kind),
827
808
CodeCompletionOperatorKind::None, /* IsSystem=*/ false,
828
809
CompletionString, /* ModuleName=*/ "", BriefDocComment,
829
- /* AssociatedUSRs=*/ {}, ContextFreeNotRecommendedReason::None,
810
+ /* AssociatedUSRs=*/ {}, ResultType,
811
+ ContextFreeNotRecommendedReason::None,
830
812
CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " ) {}
831
813
832
814
// / Constructs a \c Literal result.
@@ -835,13 +817,15 @@ class ContextFreeCodeCompletionResult {
835
817
// / result, typically by storing them in the same \c CodeCompletionResultSink
836
818
// / as the result itself.
837
819
ContextFreeCodeCompletionResult (CodeCompletionLiteralKind LiteralKind,
838
- CodeCompletionString *CompletionString)
820
+ CodeCompletionString *CompletionString,
821
+ CodeCompletionResultType ResultType)
839
822
: ContextFreeCodeCompletionResult(
840
823
CodeCompletionResultKind::Literal,
841
824
static_cast <uint8_t >(LiteralKind), CodeCompletionOperatorKind::None,
842
825
/* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " ,
843
826
/* BriefDocComment=*/ " " ,
844
- /* AssociatedUSRs=*/ {}, ContextFreeNotRecommendedReason::None,
827
+ /* AssociatedUSRs=*/ {}, ResultType,
828
+ ContextFreeNotRecommendedReason::None,
845
829
CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " ) {}
846
830
847
831
// / Constructs a \c Declaration result.
@@ -852,7 +836,7 @@ class ContextFreeCodeCompletionResult {
852
836
ContextFreeCodeCompletionResult (
853
837
CodeCompletionString *CompletionString, const Decl *AssociatedDecl,
854
838
StringRef ModuleName, StringRef BriefDocComment,
855
- ArrayRef<StringRef> AssociatedUSRs,
839
+ ArrayRef<StringRef> AssociatedUSRs, CodeCompletionResultType ResultType,
856
840
ContextFreeNotRecommendedReason NotRecommended,
857
841
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
858
842
StringRef DiagnosticMessage)
@@ -861,7 +845,7 @@ class ContextFreeCodeCompletionResult {
861
845
static_cast <uint8_t >(getCodeCompletionDeclKind(AssociatedDecl)),
862
846
CodeCompletionOperatorKind::None, getDeclIsSystem(AssociatedDecl),
863
847
CompletionString, ModuleName, BriefDocComment, AssociatedUSRs,
864
- NotRecommended, DiagnosticSeverity, DiagnosticMessage) {
848
+ ResultType, NotRecommended, DiagnosticSeverity, DiagnosticMessage) {
865
849
assert (AssociatedDecl && " should have a decl" );
866
850
}
867
851
@@ -899,6 +883,8 @@ class ContextFreeCodeCompletionResult {
899
883
900
884
ArrayRef<StringRef> getAssociatedUSRs () const { return AssociatedUSRs; }
901
885
886
+ const CodeCompletionResultType &getResultType () const { return ResultType; }
887
+
902
888
ContextFreeNotRecommendedReason getNotRecommendedReason () const {
903
889
return NotRecommended;
904
890
}
@@ -962,9 +948,7 @@ class CodeCompletionResult {
962
948
CodeCompletionResultTypeRelation TypeDistance : 3 ;
963
949
static_assert (int (CodeCompletionResultTypeRelation::MAX_VALUE) < 1 << 3 , " " );
964
950
965
- public:
966
- // / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
967
- // / information.
951
+ // / Memberwise initializer
968
952
// / The \c ContextFree result must outlive this result. Typically, this is
969
953
// / done by allocating the two in the same sink or adopting the context free
970
954
// / sink in the sink that allocates this result.
@@ -981,6 +965,23 @@ class CodeCompletionResult {
981
965
DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
982
966
TypeDistance(TypeDistance) {}
983
967
968
+ public:
969
+ // / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
970
+ // / information.
971
+ // / This computes the type relation between the completion item and its
972
+ // / expected type context.
973
+ // / The \c ContextFree result must outlive this result. Typically, this is
974
+ // / done by allocating the two in the same sink or adopting the context free
975
+ // / sink in the sink that allocates this result.
976
+ CodeCompletionResult (const ContextFreeCodeCompletionResult &ContextFree,
977
+ SemanticContextKind SemanticContext,
978
+ CodeCompletionFlair Flair, uint8_t NumBytesToErase,
979
+ const ExpectedTypeContext *TypeContext,
980
+ const DeclContext *DC,
981
+ ContextualNotRecommendedReason NotRecommended,
982
+ CodeCompletionDiagnosticSeverity DiagnosticSeverity,
983
+ StringRef DiagnosticMessage);
984
+
984
985
const ContextFreeCodeCompletionResult &getContextFreeResult () const {
985
986
return ContextFree;
986
987
}
@@ -997,7 +998,16 @@ class CodeCompletionResult {
997
998
// / context free result outlives the result the result returned by this
998
999
// / method.
999
1000
CodeCompletionResult *withFlair (CodeCompletionFlair newFlair,
1000
- CodeCompletionResultSink &Sink);
1001
+ CodeCompletionResultSink &Sink) const ;
1002
+
1003
+ // / Copy this result to \p Sink with \p newFlair . Note that this does NOT
1004
+ // / copy the context free result. Thus the caller needs to ensure that the
1005
+ // / context free result outlives the result the result returned by this
1006
+ // / method.
1007
+ CodeCompletionResult *withContextFreeResultSemanticContextAndFlair (
1008
+ const ContextFreeCodeCompletionResult &NewContextFree,
1009
+ SemanticContextKind NewSemanticContext, CodeCompletionFlair NewFlair,
1010
+ CodeCompletionResultSink &Sink) const ;
1001
1011
1002
1012
CodeCompletionResultKind getKind () const {
1003
1013
return getContextFreeResult ().getKind ();
0 commit comments