@@ -104,12 +104,15 @@ static Type defaultTypeLiteralKind(CodeCompletionLiteralKind kind,
104
104
llvm_unreachable (" Unhandled CodeCompletionLiteralKind in switch." );
105
105
}
106
106
107
- // / Whether funcType has a single argument (not including defaulted arguments)
108
- // / that is of type () -> ().
109
- static bool hasTrivialTrailingClosure (const FuncDecl *FD,
110
- AnyFunctionType *funcType) {
111
- ParameterListInfo paramInfo (funcType->getParams (), FD,
112
- /* skipCurriedSelf*/ FD->hasCurriedSelf ());
107
+ // / Whether the provided type has a single argument (not including defaulted
108
+ // / arguments) that is of type () -> ().
109
+ static bool hasTrivialTrailingClosure (const ValueDecl *VD, Type type) {
110
+ if (!VD->hasParameterList ())
111
+ return false ;
112
+
113
+ auto *funcType = type->castTo <AnyFunctionType>();
114
+ ParameterListInfo paramInfo (funcType->getParams (), VD,
115
+ /* skipCurriedSelf*/ VD->hasCurriedSelf ());
113
116
114
117
if (paramInfo.size () - paramInfo.numNonDefaultedParameters () == 1 ) {
115
118
auto param = funcType->getParams ().back ();
@@ -1947,19 +1950,21 @@ static StringRef getTypeAnnotationString(const MacroDecl *MD,
1947
1950
}
1948
1951
1949
1952
void CompletionLookup::addMacroCallArguments (const MacroDecl *MD,
1950
- DeclVisibilityKind Reason) {
1953
+ DeclVisibilityKind Reason,
1954
+ bool forTrivialTrailingClosure) {
1951
1955
CodeCompletionResultBuilder Builder =
1952
1956
makeResultBuilder (CodeCompletionResultKind::Declaration,
1953
1957
getSemanticContext (MD, Reason, DynamicLookupInfo ()));
1954
1958
Builder.setAssociatedDecl (MD);
1955
1959
1956
1960
addValueBaseName (Builder, MD->getBaseIdentifier ());
1957
1961
1958
- Type macroType = MD->getInterfaceType ();
1959
- if (MD->parameterList && MD->parameterList ->size () > 0 ) {
1962
+ if (forTrivialTrailingClosure) {
1963
+ Builder.addBraceStmtWithCursor (" { code }" );
1964
+ } else if (MD->parameterList && MD->parameterList ->size () > 0 ) {
1965
+ auto *macroTy = MD->getInterfaceType ()->castTo <AnyFunctionType>();
1960
1966
Builder.addLeftParen ();
1961
- addCallArgumentPatterns (Builder, macroType->castTo <AnyFunctionType>(),
1962
- MD->parameterList ,
1967
+ addCallArgumentPatterns (Builder, macroTy, MD->parameterList ,
1963
1968
MD->getGenericSignature ());
1964
1969
Builder.addRightParen ();
1965
1970
}
@@ -1990,6 +1995,9 @@ void CompletionLookup::addMacroExpansion(const MacroDecl *MD,
1990
1995
return ;
1991
1996
}
1992
1997
1998
+ if (hasTrivialTrailingClosure (MD, MD->getInterfaceType ()))
1999
+ addMacroCallArguments (MD, Reason, /* forTrivialTrailingClosure*/ true );
2000
+
1993
2001
addMacroCallArguments (MD, Reason);
1994
2002
}
1995
2003
0 commit comments