Skip to content

Commit b3f8625

Browse files
committed
[CodeCompletion] Add isAutoClosure flag to parameter builder
1 parent 6224d12 commit b3f8625

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21722172

21732173
Builder.addCallParameter(param->getArgumentName(), type,
21742174
param->isVariadic(), /*Outermost*/ true,
2175-
param->isInOut(), isIUO);
2175+
param->isInOut(), isIUO, param->isAutoClosure());
21762176
}
21772177
}
21782178

@@ -2270,12 +2270,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22702270
auto isIUO =
22712271
PD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
22722272
Builder.addCallParameter(argName, bodyName, ParamType,
2273-
Param.isVariadic(), /*TopLevel*/true,
2274-
Param.isInOut(), isIUO);
2275-
} else {
2276-
Builder.addCallParameter(Param.getLabel(), ParamType,
22772273
Param.isVariadic(), /*TopLevel*/ true,
2278-
Param.isInOut(), /*isIUO*/ false);
2274+
Param.isInOut(), isIUO, Param.isAutoClosure());
2275+
} else {
2276+
Builder.addCallParameter(
2277+
Param.getLabel(), ParamType, Param.isVariadic(), /*TopLevel*/ true,
2278+
Param.isInOut(), /*isIUO*/ false, Param.isAutoClosure());
22792279
}
22802280
modifiedBuilder = true;
22812281
NeedComma = true;
@@ -2490,7 +2490,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
24902490
Builder.addCallParameter(Ctx.Id_self, SelfParam.getPlainType(),
24912491
/*IsVarArg*/ false, /*TopLevel*/ true,
24922492
SelfParam.isInOut(),
2493-
/*isIUO*/ false);
2493+
/*isIUO*/ false, /*isAutoClosure*/ false);
24942494
Builder.addRightParen();
24952495
} else if (trivialTrailingClosure) {
24962496
Builder.addBraceStmtWithCursor(" { code }");
@@ -3336,7 +3336,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
33363336
assert(RHSType && resultType);
33373337
builder.addCallParameter(Identifier(), Identifier(), RHSType,
33383338
/*IsVarArg*/ false, /*TopLevel*/ true,
3339-
/*IsInOut*/ false, /*isIUO*/ false);
3339+
/*IsInOut*/ false, /*isIUO*/ false,
3340+
/*isAutoClosure*/ false);
33403341
addTypeAnnotation(builder, resultType);
33413342
}
33423343

@@ -3359,7 +3360,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
33593360
builder.addWhitespace(" ");
33603361
if (RHSType)
33613362
builder.addCallParameter(Identifier(), Identifier(), RHSType, false, true,
3362-
/*IsInOut*/ false, /*isIUO*/ false);
3363+
/*IsInOut*/ false, /*isIUO*/ false,
3364+
/*isAutoClosure*/ false);
33633365
if (resultType)
33643366
addTypeAnnotation(builder, resultType);
33653367
}
@@ -3648,19 +3650,19 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
36483650
builder.addLeftParen();
36493651
builder.addCallParameter(context.getIdentifier("red"), floatType, false,
36503652
true, /*IsInOut*/ false,
3651-
/*isIUO*/ false);
3653+
/*isIUO*/ false, /*isAutoClosure*/ false);
36523654
builder.addComma();
36533655
builder.addCallParameter(context.getIdentifier("green"), floatType, false,
3654-
true, /*IsInOut*/ false,
3655-
/*isIUO*/ false);
3656+
true, /*IsInOut*/ false, /*isIUO*/ false,
3657+
/*isAutoClosure*/ false);
36563658
builder.addComma();
36573659
builder.addCallParameter(context.getIdentifier("blue"), floatType, false,
3658-
true, /*IsInOut*/ false,
3659-
/*isIUO*/ false);
3660+
true, /*IsInOut*/ false, /*isIUO*/ false,
3661+
/*isAutoClosure*/ false);
36603662
builder.addComma();
36613663
builder.addCallParameter(context.getIdentifier("alpha"), floatType, false,
3662-
true, /*IsInOut*/ false,
3663-
/*isIUO*/ false);
3664+
true, /*IsInOut*/ false, /*isIUO*/ false,
3665+
/*isAutoClosure*/ false);
36643666
builder.addRightParen();
36653667
});
36663668

@@ -3670,7 +3672,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
36703672
builder.addLeftParen();
36713673
builder.addCallParameter(context.getIdentifier("resourceName"),
36723674
stringType, false, true, /*IsInOut*/ false,
3673-
/*isIUO*/ false);
3675+
/*isIUO*/ false, /*isAutoClosure*/ false);
36743676
builder.addRightParen();
36753677
});
36763678

lib/IDE/CodeCompletionResultBuilder.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ class CodeCompletionResultBuilder {
315315
}
316316

317317
void addCallParameter(Identifier Name, Identifier LocalName, Type Ty,
318-
bool IsVarArg, bool Outermost, bool IsInOut,
319-
bool IsIUO) {
318+
bool IsVarArg, bool Outermost, bool IsInOut, bool IsIUO,
319+
bool isAutoClosure) {
320320
CurrentNestingLevel++;
321321

322322
addSimpleChunk(CodeCompletionString::Chunk::ChunkKind::CallParameterBegin);
@@ -364,11 +364,8 @@ class CodeCompletionResultBuilder {
364364
// If the parameter is of the type @autoclosure ()->output, then the
365365
// code completion should show the parameter of the output type
366366
// instead of the function type ()->output.
367-
if (auto FuncType = Ty->getAs<AnyFunctionType>()) {
368-
if (FuncType->isAutoClosure()) {
369-
Ty = FuncType->getResult();
370-
}
371-
}
367+
if (isAutoClosure)
368+
Ty = Ty->castTo<FunctionType>()->getResult();
372369

373370
PrintOptions PO;
374371
PO.SkipAttributes = true;
@@ -378,18 +375,16 @@ class CodeCompletionResultBuilder {
378375
TypeName);
379376

380377
// Look through optional types and type aliases to find out if we have
381-
// function/closure parameter type that is not an autoclosure.
378+
// function type.
382379
Ty = Ty->lookThroughAllOptionalTypes();
383380
if (auto AFT = Ty->getAs<AnyFunctionType>()) {
384-
if (!AFT->isAutoClosure()) {
385-
// If this is a closure type, add ChunkKind::CallParameterClosureType.
386-
PrintOptions PO;
387-
PO.PrintFunctionRepresentationAttrs = false;
388-
PO.SkipAttributes = true;
389-
addChunkWithText(
390-
CodeCompletionString::Chunk::ChunkKind::CallParameterClosureType,
391-
AFT->getString(PO));
392-
}
381+
// If this is a closure type, add ChunkKind::CallParameterClosureType.
382+
PrintOptions PO;
383+
PO.PrintFunctionRepresentationAttrs = false;
384+
PO.SkipAttributes = true;
385+
addChunkWithText(
386+
CodeCompletionString::Chunk::ChunkKind::CallParameterClosureType,
387+
AFT->getString(PO));
393388
}
394389

395390
if (IsVarArg)
@@ -398,9 +393,9 @@ class CodeCompletionResultBuilder {
398393
}
399394

400395
void addCallParameter(Identifier Name, Type Ty, bool IsVarArg, bool Outermost,
401-
bool IsInOut, bool IsIUO) {
396+
bool IsInOut, bool IsIUO, bool isAutoClosure) {
402397
addCallParameter(Name, Identifier(), Ty, IsVarArg, Outermost, IsInOut,
403-
IsIUO);
398+
IsIUO, isAutoClosure);
404399
}
405400

406401
void addGenericParameter(StringRef Name) {

0 commit comments

Comments
 (0)