Skip to content

Commit a14ba63

Browse files
authored
Merge pull request swiftlang#38487 from rintaro/ide-completion-callargchunk
2 parents 93760cd + 5559d94 commit a14ba63

File tree

6 files changed

+151
-154
lines changed

6 files changed

+151
-154
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,45 +138,48 @@ class CodeCompletionStringChunk {
138138
/// Generic type parameter name.
139139
GenericParameterName,
140140

141-
/// The first chunk of a substring that describes the parameter for a
141+
/// The first chunk of a substring that describes the argument for a
142142
/// function call.
143-
CallParameterBegin,
144-
/// Function call parameter name.
145-
CallParameterName,
146-
/// Function call parameter internal / local name. If the parameter has no
147-
/// formal API name, it can still have a local name which can be useful
148-
/// for display purposes.
143+
CallArgumentBegin,
144+
145+
/// Function call argument label.
146+
CallArgumentName,
147+
148+
/// Function parameter internal / local name for an call argument. If the
149+
/// parameter has no formal API name, it can still have a local name which
150+
/// can be useful for display purposes.
149151
///
150152
/// This chunk should not be inserted into the editor buffer.
151-
CallParameterInternalName,
152-
/// A colon between parameter name and value. Should be inserted in the
153-
/// editor buffer if the preceding CallParameterName was inserted.
154-
CallParameterColon,
153+
CallArgumentInternalName,
154+
155+
/// A colon between argument name and value. Should be inserted in the
156+
/// editor buffer if the preceding CallArgumentName was inserted.
157+
CallArgumentColon,
155158

156159
/// A colon between parameter name and value. Used in decl attribute.
157160
DeclAttrParamColon,
158161

159-
/// Required parameter type.
160-
CallParameterType,
162+
/// Required argument type.
163+
CallArgumentType,
161164

162-
/// Parameter type tag for annotated results.
163-
CallParameterTypeBegin,
165+
/// Argument type tag for annotated results.
166+
CallArgumentTypeBegin,
164167

165168
/// System type name.
166169
TypeIdSystem,
167170

168171
/// Non-system type name.
169172
TypeIdUser,
170173

171-
/// Desugared closure parameter type. This can be used to get the
172-
/// closure type if CallParameterType is a TypeAliasType.
173-
CallParameterClosureType,
174+
/// Desugared closure argument type. This can be used to get the
175+
/// closure type if CallArgumentType is a TypeAliasType.
176+
CallArgumentClosureType,
174177

175-
/// An expanded closure expression for the value of a parameter, including
178+
/// An expanded closure expression for the value of an argument, including
176179
/// the left and right braces and possible signature. The preferred
177180
/// position to put the cursor after the completion result is inserted
178181
/// into the editor buffer is between the braces.
179-
CallParameterClosureExpr,
182+
CallArgumentClosureExpr,
180183

181184
/// A placeholder for \c ! or \c ? in a call to a method found by dynamic
182185
/// lookup.
@@ -212,10 +215,10 @@ class CodeCompletionStringChunk {
212215
};
213216

214217
static bool chunkStartsNestedGroup(ChunkKind Kind) {
215-
return Kind == ChunkKind::CallParameterBegin ||
218+
return Kind == ChunkKind::CallArgumentBegin ||
216219
Kind == ChunkKind::GenericParameterBegin ||
217220
Kind == ChunkKind::OptionalBegin ||
218-
Kind == ChunkKind::CallParameterTypeBegin ||
221+
Kind == ChunkKind::CallArgumentTypeBegin ||
219222
Kind == ChunkKind::TypeAnnotationBegin;
220223
}
221224

@@ -243,14 +246,14 @@ class CodeCompletionStringChunk {
243246
Kind == ChunkKind::Ampersand ||
244247
Kind == ChunkKind::Equal ||
245248
Kind == ChunkKind::Whitespace ||
246-
Kind == ChunkKind::CallParameterName ||
247-
Kind == ChunkKind::CallParameterInternalName ||
248-
Kind == ChunkKind::CallParameterColon ||
249+
Kind == ChunkKind::CallArgumentName ||
250+
Kind == ChunkKind::CallArgumentInternalName ||
251+
Kind == ChunkKind::CallArgumentColon ||
249252
Kind == ChunkKind::DeclAttrParamColon ||
250253
Kind == ChunkKind::DeclAttrParamKeyword ||
251-
Kind == ChunkKind::CallParameterType ||
252-
Kind == ChunkKind::CallParameterClosureType ||
253-
Kind == ChunkKind::CallParameterClosureExpr ||
254+
Kind == ChunkKind::CallArgumentType ||
255+
Kind == ChunkKind::CallArgumentClosureType ||
256+
Kind == ChunkKind::CallArgumentClosureExpr ||
254257
Kind == ChunkKind::GenericParameterName ||
255258
Kind == ChunkKind::DynamicLookupMethodCallTail ||
256259
Kind == ChunkKind::OptionalMethodCallTail ||

lib/IDE/CodeCompletion.cpp

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,18 @@ void CodeCompletionString::print(raw_ostream &OS) const {
411411
case ChunkKind::TypeIdUser:
412412
AnnotatedTextChunk = I->isAnnotation();
413413
LLVM_FALLTHROUGH;
414-
case ChunkKind::CallParameterName:
415-
case ChunkKind::CallParameterInternalName:
416-
case ChunkKind::CallParameterColon:
414+
case ChunkKind::CallArgumentName:
415+
case ChunkKind::CallArgumentInternalName:
416+
case ChunkKind::CallArgumentColon:
417417
case ChunkKind::DeclAttrParamColon:
418-
case ChunkKind::CallParameterType:
419-
case ChunkKind::CallParameterClosureType:
418+
case ChunkKind::CallArgumentType:
419+
case ChunkKind::CallArgumentClosureType:
420420
case ChunkKind::GenericParameterName:
421421
if (AnnotatedTextChunk)
422422
OS << "['";
423-
else if (I->getKind() == ChunkKind::CallParameterInternalName)
423+
else if (I->getKind() == ChunkKind::CallArgumentInternalName)
424424
OS << "(";
425-
else if (I->getKind() == ChunkKind::CallParameterClosureType)
425+
else if (I->getKind() == ChunkKind::CallArgumentClosureType)
426426
OS << "##";
427427
for (char Ch : I->getText()) {
428428
if (Ch == '\n')
@@ -432,12 +432,12 @@ void CodeCompletionString::print(raw_ostream &OS) const {
432432
}
433433
if (AnnotatedTextChunk)
434434
OS << "']";
435-
else if (I->getKind() == ChunkKind::CallParameterInternalName)
435+
else if (I->getKind() == ChunkKind::CallArgumentInternalName)
436436
OS << ")";
437437
break;
438438
case ChunkKind::OptionalBegin:
439-
case ChunkKind::CallParameterBegin:
440-
case ChunkKind::CallParameterTypeBegin:
439+
case ChunkKind::CallArgumentBegin:
440+
case ChunkKind::CallArgumentTypeBegin:
441441
case ChunkKind::GenericParameterBegin:
442442
OS << "{#";
443443
break;
@@ -461,7 +461,7 @@ void CodeCompletionString::print(raw_ostream &OS) const {
461461
OS << I->getText();
462462
OS << "#]";
463463
break;
464-
case ChunkKind::CallParameterClosureExpr:
464+
case ChunkKind::CallArgumentClosureExpr:
465465
OS << " {" << I->getText() << "|}";
466466
break;
467467
case ChunkKind::BraceStmtWithCursor:
@@ -924,69 +924,63 @@ class AnnotatedTypePrinter : public ASTPrinter {
924924
};
925925
} // namespcae
926926

927-
void CodeCompletionResultBuilder::addCallParameter(Identifier Name,
928-
Identifier LocalName,
929-
Type Ty,
930-
Type ContextTy,
931-
bool IsVarArg,
932-
bool IsInOut,
933-
bool IsIUO,
934-
bool isAutoClosure,
935-
bool useUnderscoreLabel,
936-
bool isLabeledTrailingClosure) {
927+
void CodeCompletionResultBuilder::addCallArgument(
928+
Identifier Name, Identifier LocalName, Type Ty, Type ContextTy,
929+
bool IsVarArg, bool IsInOut, bool IsIUO, bool isAutoClosure,
930+
bool useUnderscoreLabel, bool isLabeledTrailingClosure) {
937931
++CurrentNestingLevel;
938932
using ChunkKind = CodeCompletionString::Chunk::ChunkKind;
939933

940-
addSimpleChunk(ChunkKind::CallParameterBegin);
934+
addSimpleChunk(ChunkKind::CallArgumentBegin);
941935

942936
if (shouldAnnotateResults()) {
943937
if (!Name.empty() || !LocalName.empty()) {
944938
llvm::SmallString<16> EscapedKeyword;
945939

946940
if (!Name.empty()) {
947941
addChunkWithText(
948-
CodeCompletionString::Chunk::ChunkKind::CallParameterName,
942+
CodeCompletionString::Chunk::ChunkKind::CallArgumentName,
949943
escapeKeyword(Name.str(), false, EscapedKeyword));
950944

951945
if (!LocalName.empty() && Name != LocalName) {
952946
addChunkWithTextNoCopy(ChunkKind::Text, " ");
953947
getLastChunk().setIsAnnotation();
954-
addChunkWithText(ChunkKind::CallParameterInternalName,
948+
addChunkWithText(ChunkKind::CallArgumentInternalName,
955949
escapeKeyword(LocalName.str(), false, EscapedKeyword));
956950
getLastChunk().setIsAnnotation();
957951
}
958952
} else {
959953
assert(!LocalName.empty());
960-
addChunkWithTextNoCopy(ChunkKind::CallParameterName, "_");
954+
addChunkWithTextNoCopy(ChunkKind::CallArgumentName, "_");
961955
getLastChunk().setIsAnnotation();
962956
addChunkWithTextNoCopy(ChunkKind::Text, " ");
963957
getLastChunk().setIsAnnotation();
964-
addChunkWithText(ChunkKind::CallParameterInternalName,
958+
addChunkWithText(ChunkKind::CallArgumentInternalName,
965959
escapeKeyword(LocalName.str(), false, EscapedKeyword));
966960
}
967-
addChunkWithTextNoCopy(ChunkKind::CallParameterColon, ": ");
961+
addChunkWithTextNoCopy(ChunkKind::CallArgumentColon, ": ");
968962
}
969963
} else {
970964
if (!Name.empty()) {
971965
llvm::SmallString<16> EscapedKeyword;
972966
addChunkWithText(
973-
CodeCompletionString::Chunk::ChunkKind::CallParameterName,
967+
CodeCompletionString::Chunk::ChunkKind::CallArgumentName,
974968
escapeKeyword(Name.str(), false, EscapedKeyword));
975969
addChunkWithTextNoCopy(
976-
CodeCompletionString::Chunk::ChunkKind::CallParameterColon, ": ");
970+
CodeCompletionString::Chunk::ChunkKind::CallArgumentColon, ": ");
977971
} else if (useUnderscoreLabel) {
978972
addChunkWithTextNoCopy(
979-
CodeCompletionString::Chunk::ChunkKind::CallParameterName, "_");
973+
CodeCompletionString::Chunk::ChunkKind::CallArgumentName, "_");
980974
addChunkWithTextNoCopy(
981-
CodeCompletionString::Chunk::ChunkKind::CallParameterColon, ": ");
975+
CodeCompletionString::Chunk::ChunkKind::CallArgumentColon, ": ");
982976
} else if (!LocalName.empty()) {
983977
// Use local (non-API) parameter name if we have nothing else.
984978
llvm::SmallString<16> EscapedKeyword;
985979
addChunkWithText(
986-
CodeCompletionString::Chunk::ChunkKind::CallParameterInternalName,
980+
CodeCompletionString::Chunk::ChunkKind::CallArgumentInternalName,
987981
escapeKeyword(LocalName.str(), false, EscapedKeyword));
988982
addChunkWithTextNoCopy(
989-
CodeCompletionString::Chunk::ChunkKind::CallParameterColon, ": ");
983+
CodeCompletionString::Chunk::ChunkKind::CallArgumentColon, ": ");
990984
}
991985
}
992986

@@ -1014,13 +1008,13 @@ void CodeCompletionResultBuilder::addCallParameter(Identifier Name,
10141008
if (ContextTy)
10151009
PO.setBaseType(ContextTy);
10161010
if (shouldAnnotateResults()) {
1017-
withNestedGroup(ChunkKind::CallParameterTypeBegin, [&]() {
1011+
withNestedGroup(ChunkKind::CallArgumentTypeBegin, [&]() {
10181012
AnnotatedTypePrinter printer(*this);
10191013
Ty->print(printer, PO);
10201014
});
10211015
} else {
10221016
std::string TypeName = Ty->getString(PO);
1023-
addChunkWithText(ChunkKind::CallParameterType, TypeName);
1017+
addChunkWithText(ChunkKind::CallArgumentType, TypeName);
10241018
}
10251019

10261020
// Look through optional types and type aliases to find out if we have
@@ -1069,12 +1063,12 @@ void CodeCompletionResultBuilder::addCallParameter(Identifier Name,
10691063
OS << " in";
10701064

10711065
addChunkWithText(
1072-
CodeCompletionString::Chunk::ChunkKind::CallParameterClosureExpr,
1066+
CodeCompletionString::Chunk::ChunkKind::CallArgumentClosureExpr,
10731067
OS.str());
10741068
} else {
10751069
// Add the closure type.
10761070
addChunkWithText(
1077-
CodeCompletionString::Chunk::ChunkKind::CallParameterClosureType,
1071+
CodeCompletionString::Chunk::ChunkKind::CallArgumentClosureType,
10781072
AFT->getString(PO));
10791073
}
10801074
}
@@ -1381,8 +1375,8 @@ Optional<unsigned> CodeCompletionString::getFirstTextChunkIndex(
13811375
switch (C.getKind()) {
13821376
using ChunkKind = Chunk::ChunkKind;
13831377
case ChunkKind::Text:
1384-
case ChunkKind::CallParameterName:
1385-
case ChunkKind::CallParameterInternalName:
1378+
case ChunkKind::CallArgumentName:
1379+
case ChunkKind::CallArgumentInternalName:
13861380
case ChunkKind::GenericParameterName:
13871381
case ChunkKind::LeftParen:
13881382
case ChunkKind::LeftBracket:
@@ -1394,7 +1388,7 @@ Optional<unsigned> CodeCompletionString::getFirstTextChunkIndex(
13941388
case ChunkKind::BaseName:
13951389
case ChunkKind::TypeIdSystem:
13961390
case ChunkKind::TypeIdUser:
1397-
case ChunkKind::CallParameterBegin:
1391+
case ChunkKind::CallArgumentBegin:
13981392
return i;
13991393
case ChunkKind::Dot:
14001394
case ChunkKind::ExclamationMark:
@@ -1414,12 +1408,12 @@ Optional<unsigned> CodeCompletionString::getFirstTextChunkIndex(
14141408
case ChunkKind::OverrideKeyword:
14151409
case ChunkKind::EffectsSpecifierKeyword:
14161410
case ChunkKind::DeclIntroducer:
1417-
case ChunkKind::CallParameterColon:
1418-
case ChunkKind::CallParameterTypeBegin:
1411+
case ChunkKind::CallArgumentColon:
1412+
case ChunkKind::CallArgumentTypeBegin:
14191413
case ChunkKind::DeclAttrParamColon:
1420-
case ChunkKind::CallParameterType:
1421-
case ChunkKind::CallParameterClosureType:
1422-
case ChunkKind::CallParameterClosureExpr:
1414+
case ChunkKind::CallArgumentType:
1415+
case ChunkKind::CallArgumentClosureType:
1416+
case ChunkKind::CallArgumentClosureExpr:
14231417
case ChunkKind::OptionalBegin:
14241418
case ChunkKind::GenericParameterBegin:
14251419
case ChunkKind::DynamicLookupMethodCallTail:
@@ -2817,11 +2811,11 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
28172811
if (auto typeContext = CurrDeclContext->getInnermostTypeContext())
28182812
contextTy = typeContext->getDeclaredTypeInContext();
28192813

2820-
Builder.addCallParameter(argName, bodyName,
2821-
eraseArchetypes(paramTy, genericSig), contextTy,
2822-
isVariadic, isInOut, isIUO, isAutoclosure,
2823-
/*useUnderscoreLabel=*/false,
2824-
/*isLabeledTrailingClosure=*/false);
2814+
Builder.addCallArgument(argName, bodyName,
2815+
eraseArchetypes(paramTy, genericSig), contextTy,
2816+
isVariadic, isInOut, isIUO, isAutoclosure,
2817+
/*useUnderscoreLabel=*/false,
2818+
/*isLabeledTrailingClosure=*/false);
28252819

28262820
modifiedBuilder = true;
28272821
NeedComma = true;
@@ -4199,7 +4193,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
41994193
Type contextTy;
42004194
if (auto typeContext = CurrDeclContext->getInnermostTypeContext())
42014195
contextTy = typeContext->getDeclaredTypeInContext();
4202-
builder.addCallParameter(Identifier(), RHSType, contextTy);
4196+
builder.addCallArgument(Identifier(), RHSType, contextTy);
42034197
addTypeAnnotation(builder, resultType);
42044198
}
42054199

@@ -4224,7 +4218,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
42244218
Type contextTy;
42254219
if (auto typeContext = CurrDeclContext->getInnermostTypeContext())
42264220
contextTy = typeContext->getDeclaredTypeInContext();
4227-
builder.addCallParameter(Identifier(), RHSType, contextTy);
4221+
builder.addCallArgument(Identifier(), RHSType, contextTy);
42284222
}
42294223
if (resultType)
42304224
addTypeAnnotation(builder, resultType);
@@ -4483,21 +4477,21 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
44834477
addFromProto(LK::ColorLiteral, [&](Builder &builder) {
44844478
builder.addBaseName("#colorLiteral");
44854479
builder.addLeftParen();
4486-
builder.addCallParameter(context.getIdentifier("red"), floatType);
4480+
builder.addCallArgument(context.getIdentifier("red"), floatType);
44874481
builder.addComma();
4488-
builder.addCallParameter(context.getIdentifier("green"), floatType);
4482+
builder.addCallArgument(context.getIdentifier("green"), floatType);
44894483
builder.addComma();
4490-
builder.addCallParameter(context.getIdentifier("blue"), floatType);
4484+
builder.addCallArgument(context.getIdentifier("blue"), floatType);
44914485
builder.addComma();
4492-
builder.addCallParameter(context.getIdentifier("alpha"), floatType);
4486+
builder.addCallArgument(context.getIdentifier("alpha"), floatType);
44934487
builder.addRightParen();
44944488
});
44954489

44964490
auto stringType = context.getStringType();
44974491
addFromProto(LK::ImageLiteral, [&](Builder &builder) {
44984492
builder.addBaseName("#imageLiteral");
44994493
builder.addLeftParen();
4500-
builder.addCallParameter(context.getIdentifier("resourceName"),
4494+
builder.addCallArgument(context.getIdentifier("resourceName"),
45014495
stringType);
45024496
builder.addRightParen();
45034497
});
@@ -4697,12 +4691,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
46974691
// FIXME: SemanticContextKind::Local is not correct.
46984692
// Use 'None' (and fix prioritization) or introduce a new context.
46994693
SemanticContextKind::Local, {});
4700-
Builder.addCallParameter(Arg->getLabel(), Identifier(),
4701-
Arg->getPlainType(), ContextType,
4702-
Arg->isVariadic(), Arg->isInOut(),
4703-
/*isIUO=*/false, Arg->isAutoClosure(),
4704-
/*useUnderscoreLabel=*/true,
4705-
isLabeledTrailingClosure);
4694+
Builder.addCallArgument(Arg->getLabel(), Identifier(),
4695+
Arg->getPlainType(), ContextType,
4696+
Arg->isVariadic(), Arg->isInOut(),
4697+
/*isIUO=*/false, Arg->isAutoClosure(),
4698+
/*useUnderscoreLabel=*/true,
4699+
isLabeledTrailingClosure);
47064700
Builder.addFlair(CodeCompletionFlairBit::ArgumentLabels);
47074701
auto Ty = Arg->getPlainType();
47084702
if (Arg->isInOut()) {

0 commit comments

Comments
 (0)