@@ -104,12 +104,18 @@ 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->getAs <AnyFunctionType>();
114
+ if (!funcType)
115
+ return false ;
116
+
117
+ ParameterListInfo paramInfo (funcType->getParams (), VD,
118
+ /* skipCurriedSelf*/ VD->hasCurriedSelf ());
113
119
114
120
if (paramInfo.size () - paramInfo.numNonDefaultedParameters () == 1 ) {
115
121
auto param = funcType->getParams ().back ();
@@ -1947,19 +1953,21 @@ static StringRef getTypeAnnotationString(const MacroDecl *MD,
1947
1953
}
1948
1954
1949
1955
void CompletionLookup::addMacroCallArguments (const MacroDecl *MD,
1950
- DeclVisibilityKind Reason) {
1956
+ DeclVisibilityKind Reason,
1957
+ bool forTrivialTrailingClosure) {
1951
1958
CodeCompletionResultBuilder Builder =
1952
1959
makeResultBuilder (CodeCompletionResultKind::Declaration,
1953
1960
getSemanticContext (MD, Reason, DynamicLookupInfo ()));
1954
1961
Builder.setAssociatedDecl (MD);
1955
1962
1956
1963
addValueBaseName (Builder, MD->getBaseIdentifier ());
1957
1964
1958
- Type macroType = MD->getInterfaceType ();
1959
- if (MD->parameterList && MD->parameterList ->size () > 0 ) {
1965
+ if (forTrivialTrailingClosure) {
1966
+ Builder.addBraceStmtWithCursor (" { code }" );
1967
+ } else if (MD->parameterList && MD->parameterList ->size () > 0 ) {
1968
+ auto *macroTy = MD->getInterfaceType ()->castTo <AnyFunctionType>();
1960
1969
Builder.addLeftParen ();
1961
- addCallArgumentPatterns (Builder, macroType->castTo <AnyFunctionType>(),
1962
- MD->parameterList ,
1970
+ addCallArgumentPatterns (Builder, macroTy, MD->parameterList ,
1963
1971
MD->getGenericSignature ());
1964
1972
Builder.addRightParen ();
1965
1973
}
@@ -1990,6 +1998,9 @@ void CompletionLookup::addMacroExpansion(const MacroDecl *MD,
1990
1998
return ;
1991
1999
}
1992
2000
2001
+ if (hasTrivialTrailingClosure (MD, MD->getInterfaceType ()))
2002
+ addMacroCallArguments (MD, Reason, /* forTrivialTrailingClosure*/ true );
2003
+
1993
2004
addMacroCallArguments (MD, Reason);
1994
2005
}
1995
2006
0 commit comments