@@ -28,14 +28,16 @@ using namespace ide;
2828
2929using ChunkKind = CodeCompletionString::Chunk::ChunkKind;
3030
31+ namespace {
3132struct SignatureInfo {
32- StringRef Label ;
33+ StringRef Text ;
3334 StringRef DocComment;
3435 std::optional<unsigned > ActiveParam;
35- SmallVector<SourceKit::SignatureHelpResult ::Parameter, 1 > Params;
36+ SmallVector<SourceKit::SignatureHelpResponse ::Parameter, 1 > Params;
3637
3738 SignatureInfo () {}
3839};
40+ } // namespace
3941
4042// / \returns Array of parameters of \p VD accounting for implicitly curried
4143// / instance methods.
@@ -59,26 +61,18 @@ getParameterArray(const ValueDecl *VD, bool IsImplicitlyCurried,
5961 return {};
6062}
6163
62- static CodeCompletionString *createSignatureLabel (
64+ static CodeCompletionString *createSignatureString (
6365 llvm::BumpPtrAllocator &Allocator, ValueDecl *FD, AnyFunctionType *AFT,
6466 const DeclContext *DC, GenericSignature GenericSig, bool IsSubscript,
6567 bool IsMember, bool IsImplicitlyCurried, bool IsSecondApply) {
66- if (IsSecondApply) {
67- // Don't use the function decl when creating the signature label
68- // if this is the second apply of a double-applied function to
69- // avoid showing incorrect information like IUOs, rethrows, or
70- // reasync which can't be used in second apply.
71- FD = nullptr ;
72- }
73-
7468 CodeCompletionStringBuilder StringBuilder (
7569 Allocator, /* AnnotateResults=*/ false ,
7670 /* UnderscoreEmptyArgumentLabel=*/ !IsSubscript,
7771 /* FullParameterFlags=*/ true );
7872
7973 DeclBaseName BaseName;
8074
81- if (FD) {
75+ if (!IsSecondApply && FD) {
8276 BaseName = FD->getBaseName ();
8377 } else if (IsSubscript) {
8478 BaseName = DeclBaseName::createSubscript ();
@@ -98,11 +92,15 @@ static CodeCompletionString *createSignatureLabel(
9892 StringBuilder.addRightParen ();
9993
10094 if (!IsImplicitlyCurried) {
95+ // For a second apply, we don't pass the declaration to avoid adding
96+ // incorrect rethrows and reasync which are only usable in a single apply.
10197 StringBuilder.addEffectsSpecifiers (
102- AFT, dyn_cast_or_null<AbstractFunctionDecl>(FD));
98+ AFT,
99+ /* AFD=*/ IsSecondApply ? nullptr
100+ : dyn_cast_or_null<AbstractFunctionDecl>(FD));
103101 }
104102
105- if (!IsImplicitlyCurried && FD && FD->isImplicitlyUnwrappedOptional ())
103+ if (FD && FD->isImplicitlyUnwrappedOptional ())
106104 StringBuilder.addTypeAnnotationForImplicitlyUnwrappedOptional (
107105 AFT->getResult (), DC, GenericSig);
108106 else
@@ -129,21 +127,21 @@ static void getSignatureInfo(const DeclContext *DC, const Signature &Sig,
129127 if (FD) {
130128 IsConstructor = isa<ConstructorDecl>(FD);
131129
132- if (auto *FDC = dyn_cast<DeclContext>(FD ))
133- genericSig = FDC-> getGenericSignatureOfContext ();
130+ if (auto *GC = FD-> getAsGenericContext ( ))
131+ genericSig = GC-> getGenericSignature ();
134132 }
135133
136- auto *SignatureLabel =
137- createSignatureLabel (Allocator, FD, AFT, DC, genericSig, Sig.IsSubscript ,
138- /* IsMember=*/ bool (Sig.BaseType ),
139- Sig.IsImplicitlyCurried , Sig.IsSecondApply );
134+ auto *SignatureString =
135+ createSignatureString (Allocator, FD, AFT, DC, genericSig, Sig.IsSubscript ,
136+ /* IsMember=*/ bool (Sig.BaseType ),
137+ Sig.IsImplicitlyCurried , Sig.IsSecondApply );
140138
141139 llvm::SmallString<512 > SS;
142140 llvm::raw_svector_ostream OS (SS);
143141
144142 bool SkipResult = AFT->getResult ()->isVoid () || IsConstructor;
145143
146- auto Chunks = SignatureLabel ->getChunks ();
144+ auto Chunks = SignatureString ->getChunks ();
147145 auto C = Chunks.begin ();
148146 while (C != Chunks.end ()) {
149147 if (C->is (ChunkKind::TypeAnnotation) && SkipResult) {
@@ -159,7 +157,7 @@ static void getSignatureInfo(const DeclContext *DC, const Signature &Sig,
159157 ++C;
160158
161159 auto &P = Info.Params .emplace_back ();
162- P.LabelBegin = SS.size ();
160+ P.Offset = SS.size ();
163161
164162 do {
165163 if (!C->is (ChunkKind::CallArgumentClosureType) && C->hasText ())
@@ -168,7 +166,8 @@ static void getSignatureInfo(const DeclContext *DC, const Signature &Sig,
168166 ++C;
169167 } while (C != Chunks.end () && !C->endsPreviousNestedGroup (NestingLevel));
170168
171- P.LabelLength = SS.size () - P.LabelBegin ;
169+ P.Length = SS.size () - P.Offset ;
170+ continue ;
172171 }
173172
174173 if (C->hasText ())
@@ -177,7 +176,7 @@ static void getSignatureInfo(const DeclContext *DC, const Signature &Sig,
177176 ++C;
178177 }
179178
180- Info.Label = copyAndClearString (Allocator, SS);
179+ Info.Text = copyAndClearString (Allocator, SS);
181180 Info.ActiveParam = Sig.ParamIdx ;
182181
183182 // Documentation.
@@ -211,12 +210,12 @@ static void deliverResults(SourceKit::SignatureHelpConsumer &SKConsumer,
211210 getSignatureInfo (Result->Result ->DC , Sig, Info, Allocator);
212211 }
213212
214- SourceKit::SignatureHelpResult SKResult;
215- SmallVector<SourceKit::SignatureHelpResult ::Signature, 8 > SKSignatures;
213+ SourceKit::SignatureHelpResponse SKResult;
214+ SmallVector<SourceKit::SignatureHelpResponse ::Signature, 8 > SKSignatures;
216215
217216 for (auto &Info : Infos) {
218217 SKSignatures.push_back (
219- {Info.Label , Info.DocComment , Info.ActiveParam , Info.Params });
218+ {Info.Text , Info.DocComment , Info.ActiveParam , Info.Params });
220219 }
221220
222221 SKResult.Signatures = SKSignatures;
0 commit comments