@@ -568,6 +568,14 @@ enum class CompletionKind {
568
568
TypeAttrBeginning,
569
569
};
570
570
571
+ enum class CodeCompletionDiagnosticSeverity : uint8_t {
572
+ None,
573
+ Error,
574
+ Warning,
575
+ Remark,
576
+ Note,
577
+ };
578
+
571
579
// / A single code completion result.
572
580
class CodeCompletionResult {
573
581
friend class CodeCompletionResultBuilder ;
@@ -607,7 +615,9 @@ class CodeCompletionResult {
607
615
enum class NotRecommendedReason {
608
616
None = 0 ,
609
617
RedundantImport,
618
+ RedundantImportIndirect,
610
619
Deprecated,
620
+ SoftDeprecated,
611
621
InvalidAsyncContext,
612
622
CrossActorReference,
613
623
VariableUsedInOwnDefinition,
@@ -633,10 +643,13 @@ class CodeCompletionResult {
633
643
private:
634
644
CodeCompletionString *CompletionString;
635
645
StringRef ModuleName;
646
+ StringRef SourceFilePath;
636
647
StringRef BriefDocComment;
637
648
ArrayRef<StringRef> AssociatedUSRs;
638
649
ArrayRef<std::pair<StringRef, StringRef>> DocWords;
639
650
unsigned TypeDistance : 3 ;
651
+ unsigned DiagnosticSeverity: 3 ;
652
+ StringRef DiagnosticMessage;
640
653
641
654
public:
642
655
// / Constructs a \c Pattern, \c Keyword or \c BuiltinOperator result.
@@ -663,6 +676,7 @@ class CodeCompletionResult {
663
676
getOperatorKind () != CodeCompletionOperatorKind::None);
664
677
AssociatedKind = 0 ;
665
678
IsSystem = 0 ;
679
+ DiagnosticSeverity = 0 ;
666
680
}
667
681
668
682
// / Constructs a \c Keyword result.
@@ -683,6 +697,7 @@ class CodeCompletionResult {
683
697
assert (CompletionString);
684
698
AssociatedKind = static_cast <unsigned >(Kind);
685
699
IsSystem = 0 ;
700
+ DiagnosticSeverity = 0 ;
686
701
}
687
702
688
703
// / Constructs a \c Literal result.
@@ -700,6 +715,7 @@ class CodeCompletionResult {
700
715
TypeDistance(TypeDistance) {
701
716
AssociatedKind = static_cast <unsigned >(LiteralKind);
702
717
IsSystem = 0 ;
718
+ DiagnosticSeverity = 0 ;
703
719
assert (CompletionString);
704
720
}
705
721
@@ -727,6 +743,7 @@ class CodeCompletionResult {
727
743
assert (AssociatedDecl && " should have a decl" );
728
744
AssociatedKind = unsigned (getCodeCompletionDeclKind (AssociatedDecl));
729
745
IsSystem = getDeclIsSystem (AssociatedDecl);
746
+ DiagnosticSeverity = 0 ;
730
747
assert (CompletionString);
731
748
if (isOperator ())
732
749
KnownOperatorKind =
@@ -740,9 +757,10 @@ class CodeCompletionResult {
740
757
CodeCompletionFlair Flair, unsigned NumBytesToErase,
741
758
CodeCompletionString *CompletionString,
742
759
CodeCompletionDeclKind DeclKind, bool IsSystem,
743
- StringRef ModuleName,
760
+ StringRef ModuleName, StringRef SourceFilePath,
744
761
CodeCompletionResult::NotRecommendedReason NotRecReason,
745
- StringRef BriefDocComment,
762
+ CodeCompletionDiagnosticSeverity diagSeverity,
763
+ StringRef DiagnosticMessage, StringRef BriefDocComment,
746
764
ArrayRef<StringRef> AssociatedUSRs,
747
765
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
748
766
ExpectedTypeRelation TypeDistance,
@@ -752,9 +770,11 @@ class CodeCompletionResult {
752
770
SemanticContext(unsigned (SemanticContext)), Flair(unsigned (Flair.toRaw())),
753
771
NotRecommended(unsigned (NotRecReason)), IsSystem(IsSystem),
754
772
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
755
- ModuleName(ModuleName), BriefDocComment(BriefDocComment),
756
- AssociatedUSRs(AssociatedUSRs), DocWords(DocWords),
757
- TypeDistance(TypeDistance) {
773
+ ModuleName(ModuleName), SourceFilePath(SourceFilePath),
774
+ BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
775
+ DocWords(DocWords), TypeDistance(TypeDistance),
776
+ DiagnosticSeverity(unsigned (diagSeverity)),
777
+ DiagnosticMessage(DiagnosticMessage) {
758
778
AssociatedKind = static_cast <unsigned >(DeclKind);
759
779
assert (CompletionString);
760
780
assert (!isOperator () ||
@@ -853,6 +873,29 @@ class CodeCompletionResult {
853
873
return DocWords;
854
874
}
855
875
876
+ void setSourceFilePath (StringRef value) {
877
+ SourceFilePath = value;
878
+ }
879
+
880
+ void setDiagnostics (CodeCompletionDiagnosticSeverity severity, StringRef message) {
881
+ DiagnosticSeverity = static_cast <unsigned >(severity);
882
+ DiagnosticMessage = message;
883
+ }
884
+
885
+ CodeCompletionDiagnosticSeverity getDiagnosticSeverity () const {
886
+ return static_cast <CodeCompletionDiagnosticSeverity>(DiagnosticSeverity);
887
+ }
888
+
889
+ StringRef getDiagnosticMessage () const {
890
+ return DiagnosticMessage;
891
+ }
892
+
893
+ // / Returns the source file path where the associated decl was declared.
894
+ // / Returns an empty string if the information is not available.
895
+ StringRef getSourceFilePath () const {
896
+ return SourceFilePath;
897
+ }
898
+
856
899
// / Print a debug representation of the code completion result to \p OS.
857
900
void printPrefix (raw_ostream &OS) const ;
858
901
SWIFT_DEBUG_DUMP;
@@ -865,6 +908,15 @@ class CodeCompletionResult {
865
908
static bool getDeclIsSystem (const Decl *D);
866
909
};
867
910
911
+ // / A pair of a file path and its up-to-date-ness.
912
+ struct SourceFileAndUpToDate {
913
+ StringRef FilePath;
914
+ bool IsUpToDate;
915
+
916
+ SourceFileAndUpToDate (StringRef FilePath, bool IsUpToDate)
917
+ : FilePath(FilePath), IsUpToDate(IsUpToDate) {}
918
+ };
919
+
868
920
struct CodeCompletionResultSink {
869
921
using AllocatorPtr = std::shared_ptr<llvm::BumpPtrAllocator>;
870
922
@@ -877,11 +929,13 @@ struct CodeCompletionResultSink {
877
929
878
930
// / Whether to annotate the results with XML.
879
931
bool annotateResult = false ;
932
+ bool requiresSourceFileInfo = false ;
880
933
881
934
// / Whether to emit object literals if desired.
882
935
bool includeObjectLiterals = true ;
883
936
884
937
std::vector<CodeCompletionResult *> Results;
938
+ std::vector<SourceFileAndUpToDate> SourceFiles;
885
939
886
940
// / A single-element cache for module names stored in Allocator, keyed by a
887
941
// / clang::Module * or swift::ModuleDecl *.
@@ -950,7 +1004,10 @@ class CodeCompletionContext {
950
1004
: Cache(Cache) {}
951
1005
952
1006
void setAnnotateResult (bool flag) { CurrentResults.annotateResult = flag; }
953
- bool getAnnotateResult () { return CurrentResults.annotateResult ; }
1007
+ bool getAnnotateResult () const { return CurrentResults.annotateResult ; }
1008
+
1009
+ void setRequiresSourceFileInfo (bool flag) { CurrentResults.requiresSourceFileInfo = flag; }
1010
+ bool requiresSourceFileInfo () const { return CurrentResults.requiresSourceFileInfo ; }
954
1011
955
1012
void setIncludeObjectLiterals (bool flag) {
956
1013
CurrentResults.includeObjectLiterals = flag;
@@ -995,8 +1052,7 @@ struct SimpleCachingCodeCompletionConsumer : public CodeCompletionConsumer {
995
1052
DeclContext *DCForModules) override ;
996
1053
997
1054
// / Clients should override this method to receive \p Results.
998
- virtual void handleResults (
999
- MutableArrayRef<CodeCompletionResult *> Results) = 0;
1055
+ virtual void handleResults (CodeCompletionContext &context) = 0;
1000
1056
};
1001
1057
1002
1058
// / A code completion result consumer that prints the results to a
@@ -1007,6 +1063,7 @@ class PrintingCodeCompletionConsumer
1007
1063
bool IncludeKeywords;
1008
1064
bool IncludeComments;
1009
1065
bool PrintAnnotatedDescription;
1066
+ bool RequiresSourceFileInfo = false ;
1010
1067
1011
1068
public:
1012
1069
PrintingCodeCompletionConsumer (llvm::raw_ostream &OS,
@@ -1018,7 +1075,8 @@ class PrintingCodeCompletionConsumer
1018
1075
IncludeComments(IncludeComments),
1019
1076
PrintAnnotatedDescription(PrintAnnotatedDescription) {}
1020
1077
1021
- void handleResults (MutableArrayRef<CodeCompletionResult *> Results) override ;
1078
+ void handleResults (CodeCompletionContext &context) override ;
1079
+ void handleResults (MutableArrayRef<CodeCompletionResult *> Results);
1022
1080
};
1023
1081
1024
1082
// / Create a factory for code completion callbacks.
0 commit comments