@@ -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 ();
@@ -1946,34 +1952,22 @@ static StringRef getTypeAnnotationString(const MacroDecl *MD,
1946
1952
return {stash.data (), stash.size ()};
1947
1953
}
1948
1954
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) {
1965
1958
CodeCompletionResultBuilder Builder =
1966
1959
makeResultBuilder (CodeCompletionResultKind::Declaration,
1967
1960
getSemanticContext (MD, Reason, DynamicLookupInfo ()));
1968
1961
Builder.setAssociatedDecl (MD);
1969
1962
1970
1963
addValueBaseName (Builder, MD->getBaseIdentifier ());
1971
1964
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>();
1974
1969
Builder.addLeftParen ();
1975
- addCallArgumentPatterns (Builder, macroType->castTo <AnyFunctionType>(),
1976
- MD->parameterList ,
1970
+ addCallArgumentPatterns (Builder, macroTy, MD->parameterList ,
1977
1971
MD->getGenericSignature ());
1978
1972
Builder.addRightParen ();
1979
1973
}
@@ -1988,6 +1982,28 @@ void CompletionLookup::addMacroExpansion(const MacroDecl *MD,
1988
1982
}
1989
1983
}
1990
1984
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
+
1991
2007
void CompletionLookup::addKeyword (StringRef Name, Type TypeAnnotation,
1992
2008
SemanticContextKind SK,
1993
2009
CodeCompletionKeywordKind KeyKind,
0 commit comments