@@ -75,9 +75,6 @@ struct SwiftToSourceKitCompletionAdapter {
75
75
bool legacyLiteralToKeyword,
76
76
bool annotatedDescription);
77
77
78
- static void getResultSourceText (const CodeCompletionString *CCStr,
79
- raw_ostream &OS);
80
-
81
78
static void getResultAssociatedUSRs (ArrayRef<StringRef> AssocUSRs,
82
79
raw_ostream &OS);
83
80
};
@@ -466,7 +463,7 @@ bool SwiftToSourceKitCompletionAdapter::handleResult(
466
463
unsigned TextBegin = SS.size ();
467
464
{
468
465
llvm::raw_svector_ostream ccOS (SS);
469
- getResultSourceText ( Result-> getCompletionString () , ccOS);
466
+ ide::printCodeCompletionResultSourceText (* Result, ccOS);
470
467
}
471
468
unsigned TextEnd = SS.size ();
472
469
@@ -603,121 +600,6 @@ getCodeCompletionKeywordKindForUID(UIdent uid) {
603
600
return CodeCompletionKeywordKind::None;
604
601
}
605
602
606
- using ChunkKind = CodeCompletionString::Chunk::ChunkKind;
607
-
608
- // / Provide the text for the call parameter, including constructing a typed
609
- // / editor placeholder for it.
610
- static void constructTextForCallParam (
611
- ArrayRef<CodeCompletionString::Chunk> ParamGroup, raw_ostream &OS) {
612
- assert (ParamGroup.front ().is (ChunkKind::CallParameterBegin));
613
-
614
- for (; !ParamGroup.empty (); ParamGroup = ParamGroup.slice (1 )) {
615
- auto &C = ParamGroup.front ();
616
- if (C.isAnnotation ())
617
- continue ;
618
- if (C.is (ChunkKind::CallParameterInternalName) ||
619
- C.is (ChunkKind::CallParameterType) ||
620
- C.is (ChunkKind::CallParameterTypeBegin) ||
621
- C.is (ChunkKind::CallParameterClosureExpr)) {
622
- break ;
623
- }
624
- if (!C.hasText ())
625
- continue ;
626
- OS << C.getText ();
627
- }
628
-
629
- SmallString<32 > DisplayString;
630
- SmallString<32 > TypeString;
631
- SmallString<32 > ExpansionTypeString;
632
-
633
- for (auto i = ParamGroup.begin (), e = ParamGroup.end (); i != e; ++i) {
634
- auto &C = *i;
635
- if (C.is (ChunkKind::CallParameterTypeBegin)) {
636
- assert (TypeString.empty ());
637
- auto nestingLevel = C.getNestingLevel ();
638
- ++i;
639
- for (; i != e; ++i) {
640
- if (i->endsPreviousNestedGroup (nestingLevel))
641
- break ;
642
- if (!i->isAnnotation () && i->hasText ()) {
643
- TypeString += i->getText ();
644
- DisplayString += i->getText ();
645
- }
646
- }
647
- --i;
648
- continue ;
649
- }
650
- if (C.is (ChunkKind::CallParameterClosureType)) {
651
- assert (ExpansionTypeString.empty ());
652
- ExpansionTypeString = C.getText ();
653
- continue ;
654
- }
655
- if (C.is (ChunkKind::CallParameterType)) {
656
- assert (TypeString.empty ());
657
- TypeString = C.getText ();
658
- }
659
- if (C.is (ChunkKind::CallParameterClosureExpr)) {
660
- // We have a closure expression, so provide it directly instead of in
661
- // a placeholder.
662
- OS << " {" ;
663
- if (!C.getText ().empty ())
664
- OS << " " << C.getText ();
665
- OS << " \n " << getCodePlaceholder () << " \n }" ;
666
- return ;
667
- }
668
- if (C.isAnnotation () || !C.hasText ())
669
- continue ;
670
- DisplayString += C.getText ();
671
- }
672
-
673
- StringRef Display = DisplayString.str ();
674
- StringRef Type = TypeString.str ();
675
- StringRef ExpansionType = ExpansionTypeString.str ();
676
- if (ExpansionType.empty ())
677
- ExpansionType = Type;
678
-
679
- OS << " <#T##" << Display;
680
- if (Display == Type && Display == ExpansionType) {
681
- // Short version, display and type are the same.
682
- } else {
683
- OS << " ##" << Type;
684
- if (ExpansionType != Type)
685
- OS << " ##" << ExpansionType;
686
- }
687
- OS << " #>" ;
688
- }
689
-
690
- void SwiftToSourceKitCompletionAdapter::getResultSourceText (
691
- const CodeCompletionString *CCStr, raw_ostream &OS) {
692
- auto Chunks = CCStr->getChunks ();
693
- for (size_t i = 0 ; i < Chunks.size (); ++i) {
694
- auto &C = Chunks[i];
695
- if (C.is (ChunkKind::BraceStmtWithCursor)) {
696
- OS << " {\n " << getCodePlaceholder () << " \n }" ;
697
- continue ;
698
- }
699
- if (C.is (ChunkKind::CallParameterBegin)) {
700
- size_t Start = i++;
701
- for (; i < Chunks.size (); ++i) {
702
- if (Chunks[i].endsPreviousNestedGroup (C.getNestingLevel ()))
703
- break ;
704
- }
705
- constructTextForCallParam (Chunks.slice (Start, i-Start), OS);
706
- --i;
707
- continue ;
708
- }
709
- if (C.is (ChunkKind::TypeAnnotationBegin)) {
710
- // Skip type annotation structure.
711
- auto level = C.getNestingLevel ();
712
- do { ++i; } while (i != Chunks.size () && !Chunks[i].endsPreviousNestedGroup (level));
713
- --i;
714
- }
715
- if (!C.isAnnotation () && C.hasText ()) {
716
- OS << C.getText ();
717
- }
718
- }
719
- }
720
-
721
603
void SwiftToSourceKitCompletionAdapter::getResultAssociatedUSRs (
722
604
ArrayRef<StringRef> AssocUSRs, raw_ostream &OS) {
723
605
bool First = true ;
@@ -1140,8 +1022,7 @@ static void transformAndForwardResults(
1140
1022
std::string str = inputBuf->getBuffer ().slice (0 , offset).str ();
1141
1023
{
1142
1024
llvm::raw_string_ostream OSS (str);
1143
- SwiftToSourceKitCompletionAdapter::getResultSourceText (
1144
- exactMatch->getCompletionString (), OSS);
1025
+ ide::printCodeCompletionResultSourceText (*exactMatch, OSS);
1145
1026
}
1146
1027
1147
1028
auto buffer =
0 commit comments