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"
@@ -724,6 +725,7 @@ class ContextFreeCodeCompletionResult {
724
725
StringRef ModuleName;
725
726
StringRef BriefDocComment;
726
727
ArrayRef<StringRef> AssociatedUSRs;
728
+ CodeCompletionResultType ResultType;
727
729
728
730
ContextFreeNotRecommendedReason NotRecommended : 3 ;
729
731
static_assert (int (ContextFreeNotRecommendedReason::MAX_VALUE) < 1 << 3 , " " );
@@ -747,13 +749,15 @@ class ContextFreeCodeCompletionResult {
747
749
CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem,
748
750
CodeCompletionString *CompletionString, StringRef ModuleName,
749
751
StringRef BriefDocComment, ArrayRef<StringRef> AssociatedUSRs,
752
+ CodeCompletionResultType ResultType,
750
753
ContextFreeNotRecommendedReason NotRecommended,
751
754
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
752
755
StringRef DiagnosticMessage)
753
756
: Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
754
757
CompletionString (CompletionString), ModuleName(ModuleName),
755
758
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
756
- NotRecommended(NotRecommended), DiagnosticSeverity(DiagnosticSeverity),
759
+ ResultType(ResultType), NotRecommended(NotRecommended),
760
+ DiagnosticSeverity(DiagnosticSeverity),
757
761
DiagnosticMessage(DiagnosticMessage) {
758
762
this ->AssociatedKind .Opaque = AssociatedKind;
759
763
assert ((NotRecommended == ContextFreeNotRecommendedReason::None) ==
@@ -780,13 +784,14 @@ class ContextFreeCodeCompletionResult {
780
784
ContextFreeCodeCompletionResult (
781
785
CodeCompletionResultKind Kind, CodeCompletionString *CompletionString,
782
786
CodeCompletionOperatorKind KnownOperatorKind, StringRef BriefDocComment,
787
+ CodeCompletionResultType ResultType,
783
788
ContextFreeNotRecommendedReason NotRecommended,
784
789
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
785
790
StringRef DiagnosticMessage)
786
791
: ContextFreeCodeCompletionResult(
787
792
Kind, /* AssociatedKind=*/ 0 , KnownOperatorKind,
788
793
/* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " ,
789
- BriefDocComment, /* AssociatedUSRs=*/ {}, NotRecommended,
794
+ BriefDocComment, /* AssociatedUSRs=*/ {}, ResultType, NotRecommended,
790
795
DiagnosticSeverity, DiagnosticMessage) {}
791
796
792
797
// / Constructs a \c Keyword result.
@@ -796,12 +801,14 @@ class ContextFreeCodeCompletionResult {
796
801
// / same \c CodeCompletionResultSink as the result itself.
797
802
ContextFreeCodeCompletionResult (CodeCompletionKeywordKind Kind,
798
803
CodeCompletionString *CompletionString,
799
- StringRef BriefDocComment)
804
+ StringRef BriefDocComment,
805
+ CodeCompletionResultType ResultType)
800
806
: ContextFreeCodeCompletionResult(
801
807
CodeCompletionResultKind::Keyword, static_cast <uint8_t >(Kind),
802
808
CodeCompletionOperatorKind::None, /* IsSystem=*/ false,
803
809
CompletionString, /* ModuleName=*/ "", BriefDocComment,
804
- /* AssociatedUSRs=*/ {}, ContextFreeNotRecommendedReason::None,
810
+ /* AssociatedUSRs=*/ {}, ResultType,
811
+ ContextFreeNotRecommendedReason::None,
805
812
CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " ) {}
806
813
807
814
// / Constructs a \c Literal result.
@@ -810,13 +817,15 @@ class ContextFreeCodeCompletionResult {
810
817
// / result, typically by storing them in the same \c CodeCompletionResultSink
811
818
// / as the result itself.
812
819
ContextFreeCodeCompletionResult (CodeCompletionLiteralKind LiteralKind,
813
- CodeCompletionString *CompletionString)
820
+ CodeCompletionString *CompletionString,
821
+ CodeCompletionResultType ResultType)
814
822
: ContextFreeCodeCompletionResult(
815
823
CodeCompletionResultKind::Literal,
816
824
static_cast <uint8_t >(LiteralKind), CodeCompletionOperatorKind::None,
817
825
/* IsSystem=*/ false , CompletionString, /* ModuleName=*/ " " ,
818
826
/* BriefDocComment=*/ " " ,
819
- /* AssociatedUSRs=*/ {}, ContextFreeNotRecommendedReason::None,
827
+ /* AssociatedUSRs=*/ {}, ResultType,
828
+ ContextFreeNotRecommendedReason::None,
820
829
CodeCompletionDiagnosticSeverity::None, /* DiagnosticMessage=*/ " " ) {}
821
830
822
831
// / Constructs a \c Declaration result.
@@ -827,7 +836,7 @@ class ContextFreeCodeCompletionResult {
827
836
ContextFreeCodeCompletionResult (
828
837
CodeCompletionString *CompletionString, const Decl *AssociatedDecl,
829
838
StringRef ModuleName, StringRef BriefDocComment,
830
- ArrayRef<StringRef> AssociatedUSRs,
839
+ ArrayRef<StringRef> AssociatedUSRs, CodeCompletionResultType ResultType,
831
840
ContextFreeNotRecommendedReason NotRecommended,
832
841
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
833
842
StringRef DiagnosticMessage)
@@ -836,7 +845,7 @@ class ContextFreeCodeCompletionResult {
836
845
static_cast <uint8_t >(getCodeCompletionDeclKind(AssociatedDecl)),
837
846
CodeCompletionOperatorKind::None, getDeclIsSystem(AssociatedDecl),
838
847
CompletionString, ModuleName, BriefDocComment, AssociatedUSRs,
839
- NotRecommended, DiagnosticSeverity, DiagnosticMessage) {
848
+ ResultType, NotRecommended, DiagnosticSeverity, DiagnosticMessage) {
840
849
assert (AssociatedDecl && " should have a decl" );
841
850
}
842
851
@@ -874,6 +883,8 @@ class ContextFreeCodeCompletionResult {
874
883
875
884
ArrayRef<StringRef> getAssociatedUSRs () const { return AssociatedUSRs; }
876
885
886
+ const CodeCompletionResultType &getResultType () const { return ResultType; }
887
+
877
888
ContextFreeNotRecommendedReason getNotRecommendedReason () const {
878
889
return NotRecommended;
879
890
}
@@ -909,34 +920,6 @@ class ContextFreeCodeCompletionResult {
909
920
// / A single code completion result enriched with information that depend on
910
921
// / the completion's usage context.
911
922
class CodeCompletionResult {
912
- public:
913
- // / Describes the relationship between the type of the completion results and
914
- // / the expected type at the code completion position.
915
- enum class ExpectedTypeRelation : uint8_t {
916
- // / The result does not have a type (e.g. keyword).
917
- NotApplicable,
918
-
919
- // / The type relation have not been calculated.
920
- Unknown,
921
-
922
- // / The relationship of the result's type to the expected type is not
923
- // / invalid, not convertible, and not identical.
924
- Unrelated,
925
-
926
- // / The result's type is invalid at the expected position.
927
- Invalid,
928
-
929
- // / The result's type is convertible to the type of the expected.
930
- Convertible,
931
-
932
- // / The result's type is identical to the type of the expected.
933
- Identical,
934
-
935
- MAX_VALUE = Identical
936
- };
937
-
938
-
939
- private:
940
923
const ContextFreeCodeCompletionResult &ContextFree;
941
924
SemanticContextKind SemanticContext : 3 ;
942
925
static_assert (int (SemanticContextKind::MAX_VALUE) < 1 << 3 , " " );
@@ -962,17 +945,17 @@ class CodeCompletionResult {
962
945
static const unsigned MaxNumBytesToErase = 127 ;
963
946
964
947
private:
965
- ExpectedTypeRelation TypeDistance : 3 ;
966
- public:
967
- // / Enrich a \c ContextFreeCodeCompletionResult with the following contextual
968
- // / information.
948
+ CodeCompletionResultTypeRelation TypeDistance : 3 ;
949
+ static_assert ( int (CodeCompletionResultTypeRelation::MAX_VALUE) < 1 << 3 , " " );
950
+
951
+ // / Memberwise initializer
969
952
// / The \c ContextFree result must outlive this result. Typically, this is
970
953
// / done by allocating the two in the same sink or adopting the context free
971
954
// / sink in the sink that allocates this result.
972
955
CodeCompletionResult (const ContextFreeCodeCompletionResult &ContextFree,
973
956
SemanticContextKind SemanticContext,
974
957
CodeCompletionFlair Flair, uint8_t NumBytesToErase,
975
- ExpectedTypeRelation TypeDistance,
958
+ CodeCompletionResultTypeRelation TypeDistance,
976
959
ContextualNotRecommendedReason NotRecommended,
977
960
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
978
961
StringRef DiagnosticMessage)
@@ -982,6 +965,23 @@ class CodeCompletionResult {
982
965
DiagnosticMessage(DiagnosticMessage), NumBytesToErase(NumBytesToErase),
983
966
TypeDistance(TypeDistance) {}
984
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
+
985
985
const ContextFreeCodeCompletionResult &getContextFreeResult () const {
986
986
return ContextFree;
987
987
}
@@ -998,7 +998,16 @@ class CodeCompletionResult {
998
998
// / context free result outlives the result the result returned by this
999
999
// / method.
1000
1000
CodeCompletionResult *withFlair (CodeCompletionFlair newFlair,
1001
- 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 ;
1002
1011
1003
1012
CodeCompletionResultKind getKind () const {
1004
1013
return getContextFreeResult ().getKind ();
@@ -1024,7 +1033,9 @@ class CodeCompletionResult {
1024
1033
1025
1034
bool isSystem () const { return getContextFreeResult ().isSystem (); }
1026
1035
1027
- ExpectedTypeRelation getExpectedTypeRelation () const { return TypeDistance; }
1036
+ CodeCompletionResultTypeRelation getExpectedTypeRelation () const {
1037
+ return TypeDistance;
1038
+ }
1028
1039
1029
1040
// / Get the contextual not-recommended reason. This disregards context-free
1030
1041
// / not recommended reasons.
0 commit comments