@@ -104,12 +104,18 @@ static Type defaultTypeLiteralKind(CodeCompletionLiteralKind kind,
104104 llvm_unreachable (" Unhandled CodeCompletionLiteralKind in switch." );
105105}
106106
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 ());
113119
114120 if (paramInfo.size () - paramInfo.numNonDefaultedParameters () == 1 ) {
115121 auto param = funcType->getParams ().back ();
@@ -1947,19 +1953,21 @@ static StringRef getTypeAnnotationString(const MacroDecl *MD,
19471953}
19481954
19491955void CompletionLookup::addMacroCallArguments (const MacroDecl *MD,
1950- DeclVisibilityKind Reason) {
1956+ DeclVisibilityKind Reason,
1957+ bool forTrivialTrailingClosure) {
19511958 CodeCompletionResultBuilder Builder =
19521959 makeResultBuilder (CodeCompletionResultKind::Declaration,
19531960 getSemanticContext (MD, Reason, DynamicLookupInfo ()));
19541961 Builder.setAssociatedDecl (MD);
19551962
19561963 addValueBaseName (Builder, MD->getBaseIdentifier ());
19571964
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>();
19601969 Builder.addLeftParen ();
1961- addCallArgumentPatterns (Builder, macroType->castTo <AnyFunctionType>(),
1962- MD->parameterList ,
1970+ addCallArgumentPatterns (Builder, macroTy, MD->parameterList ,
19631971 MD->getGenericSignature ());
19641972 Builder.addRightParen ();
19651973 }
@@ -1990,6 +1998,9 @@ void CompletionLookup::addMacroExpansion(const MacroDecl *MD,
19901998 return ;
19911999 }
19922000
2001+ if (hasTrivialTrailingClosure (MD, MD->getInterfaceType ()))
2002+ addMacroCallArguments (MD, Reason, /* forTrivialTrailingClosure*/ true );
2003+
19932004 addMacroCallArguments (MD, Reason);
19942005}
19952006
0 commit comments