@@ -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 ();
@@ -1946,34 +1952,22 @@ static StringRef getTypeAnnotationString(const MacroDecl *MD,
19461952 return {stash.data (), stash.size ()};
19471953}
19481954
1949- void CompletionLookup::addMacroExpansion (const MacroDecl *MD,
1950- DeclVisibilityKind Reason) {
1951- if (!MD->hasName () || !MD->isAccessibleFrom (CurrDeclContext) ||
1952- MD->shouldHideFromEditor ())
1953- return ;
1954-
1955- OptionSet<CustomAttributeKind> expectedKinds =
1956- expectedTypeContext.getExpectedCustomAttributeKinds ();
1957- if (expectedKinds) {
1958- CodeCompletionMacroRoles expectedRoles =
1959- getCompletionMacroRoles (expectedKinds);
1960- CodeCompletionMacroRoles roles = getCompletionMacroRoles (MD);
1961- if (!(roles & expectedRoles))
1962- return ;
1963- }
1964-
1955+ void CompletionLookup::addMacroCallArguments (const MacroDecl *MD,
1956+ DeclVisibilityKind Reason,
1957+ bool forTrivialTrailingClosure) {
19651958 CodeCompletionResultBuilder Builder =
19661959 makeResultBuilder (CodeCompletionResultKind::Declaration,
19671960 getSemanticContext (MD, Reason, DynamicLookupInfo ()));
19681961 Builder.setAssociatedDecl (MD);
19691962
19701963 addValueBaseName (Builder, MD->getBaseIdentifier ());
19711964
1972- Type macroType = MD->getInterfaceType ();
1973- 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>();
19741969 Builder.addLeftParen ();
1975- addCallArgumentPatterns (Builder, macroType->castTo <AnyFunctionType>(),
1976- MD->parameterList ,
1970+ addCallArgumentPatterns (Builder, macroTy, MD->parameterList ,
19771971 MD->getGenericSignature ());
19781972 Builder.addRightParen ();
19791973 }
@@ -1988,6 +1982,28 @@ void CompletionLookup::addMacroExpansion(const MacroDecl *MD,
19881982 }
19891983}
19901984
1985+ void CompletionLookup::addMacroExpansion (const MacroDecl *MD,
1986+ DeclVisibilityKind Reason) {
1987+ if (!MD->hasName () || !MD->isAccessibleFrom (CurrDeclContext) ||
1988+ MD->shouldHideFromEditor ())
1989+ return ;
1990+
1991+ OptionSet<CustomAttributeKind> expectedKinds =
1992+ expectedTypeContext.getExpectedCustomAttributeKinds ();
1993+ if (expectedKinds) {
1994+ CodeCompletionMacroRoles expectedRoles =
1995+ getCompletionMacroRoles (expectedKinds);
1996+ CodeCompletionMacroRoles roles = getCompletionMacroRoles (MD);
1997+ if (!(roles & expectedRoles))
1998+ return ;
1999+ }
2000+
2001+ if (hasTrivialTrailingClosure (MD, MD->getInterfaceType ()))
2002+ addMacroCallArguments (MD, Reason, /* forTrivialTrailingClosure*/ true );
2003+
2004+ addMacroCallArguments (MD, Reason);
2005+ }
2006+
19912007void CompletionLookup::addKeyword (StringRef Name, Type TypeAnnotation,
19922008 SemanticContextKind SK,
19932009 CodeCompletionKeywordKind KeyKind,
0 commit comments