Skip to content
Permalink
Browse files

[Code completion] Test and fix 'static func' for function builder met…

…hods.
  • Loading branch information
DougGregor committed Sep 16, 2020
1 parent 23b6b40 commit 25cd671ed5b0f17a5f257c265031ed23d6264010
@@ -5316,7 +5316,7 @@ NOTE(function_builder_missing_build_optional, none,
"add 'buildOptional(_:)' to the function builder %0 to add support for "
"'if' statements without an 'else'", (Type))
NOTE(function_builder_missing_build_either, none,
"add 'buildEither(first:)' and `buildEither(second:)' to the function "
"add 'buildEither(first:)' and 'buildEither(second:)' to the function "
"builder %0 to add support for 'if'-'else' and 'switch'", (Type))
NOTE(function_builder_missing_build_array, none,
"add 'buildArray(_:)' to the function builder %0 to add support for "
@@ -5170,7 +5170,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
"outermost block statement to produce the final returned result";

case FunctionBuilderBuildFunction::BuildLimitedAvailability:
return "If declaration, this will be called on the partial result of "
return "If declared, this will be called on the partial result of "
"an 'if #available' block to allow the function builder to erase "
"type information";

@@ -5195,9 +5195,9 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
Builder.addAccessControlKeyword(AccessLevel::Public);

if (!hasStaticOrClass)
Builder.addKeyword("static");
Builder.addTextChunk("static ");

Builder.addKeyword("func");
Builder.addTextChunk("func ");
}

std::string declStringWithoutFunc;
@@ -47,7 +47,7 @@ struct TupleBuilder { // expected-note 2 {{struct 'TupleBuilder' declared here}}
@_functionBuilder
struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf' declared here}}
// expected-note@-1{{add 'buildOptional(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if' statements without an 'else'}}{{31-31=\n static func buildOptional(_ component: <#Component#>?) -> <#Component#> {\n <#code#>\n \}}}
// expected-note@-2{{add 'buildEither(first:)' and `buildEither(second:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if'-'else' and 'switch'}}{{31-31=\n static func buildEither(first component: <#Component#>) -> <#Component#> {\n <#code#>\n \}\n\n static func buildEither(second component: <#Component#>) -> <#Component#> {\n <#code#>\n \}}}
// expected-note@-2{{add 'buildEither(first:)' and 'buildEither(second:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'if'-'else' and 'switch'}}{{31-31=\n static func buildEither(first component: <#Component#>) -> <#Component#> {\n <#code#>\n \}\n\n static func buildEither(second component: <#Component#>) -> <#Component#> {\n <#code#>\n \}}}
// expected-note@-3{{add 'buildArray(_:)' to the function builder 'TupleBuilderWithoutIf' to add support for 'for'..'in' loops}}{{31-31=\n static func buildArray(_ components: [<#Component#>]) -> <#Component#> {\n <#code#>\n \}}}
static func buildBlock() -> () { }

@@ -2,6 +2,7 @@
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_NONTOP | %FileCheck %s -check-prefix=IN_CLOSURE_TOP
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_COLOR_CONTEXT | %FileCheck %s -check-prefix=IN_CLOSURE_COLOR_CONTEXT
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_FUNCTION_BUILDER_DECL -code-completion-comments=true | %FileCheck %s -check-prefix=IN_FUNCTION_BUILDER_DECL
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_FUNCTION_BUILDER_DECL_PREFIX -code-completion-comments=true | %FileCheck %s -check-prefix=IN_FUNCTION_BUILDER_DECL_PREFIX
struct Tagged<Tag, Entity> {
let tag: Tag
@@ -99,6 +100,8 @@ func acceptBuilder(@EnumToVoidBuilder body: () -> Void) {}
struct AnyBuilder {
static func buildBlock(_ components: Any...) -> Any { 5 }

#^IN_FUNCTION_BUILDER_DECL_PREFIX^#

static func #^IN_FUNCTION_BUILDER_DECL^#
}

@@ -112,3 +115,14 @@ struct AnyBuilder {
// IN_FUNCTION_BUILDER_DECL: Pattern/CurrNominal: buildLimitedAvailability(_ component: Any) -> Any {|}; name=buildLimitedAvailability(_ component: Any) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL: Pattern/CurrNominal: buildFinalResult(_ component: Any) -> <#Result#> {|}; name=buildFinalResult(_ component: Any) -> <#Result#>; comment=
// IN_FUNCTION_BUILDER_DECL: End completions
// IN_FUNCTION_BUILDER_DECL_PREFIX: Begin completions
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildBlock(_ components: Any...) -> Any {|}; name=static func buildBlock(_ components: Any...) -> Any; comment=Required by every
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildExpression(_ expression: <#Expression#>) -> Any {|}; name=static func buildExpression(_ expression: <#Expression#>) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildOptional(_ component: Any?) -> Any {|}; name=static func buildOptional(_ component: Any?) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildEither(first component: Any) -> Any {|}; name=static func buildEither(first component: Any) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildEither(second component: Any) -> Any {|}; name=static func buildEither(second component: Any) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildArray(_ components: [Any]) -> Any {|}; name=static func buildArray(_ components: [Any]) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildLimitedAvailability(_ component: Any) -> Any {|}; name=static func buildLimitedAvailability(_ component: Any) -> Any; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildFinalResult(_ component: Any) -> <#Result#> {|}; name=static func buildFinalResult(_ component: Any) -> <#Result#>; comment=
// IN_FUNCTION_BUILDER_DECL_PREFIX: End completions
@@ -44,7 +44,7 @@ struct ExampleFunctionBuilder {
/// results of all iterations into a single result.
static func buildArray(_ components: [Component]) -> Component { ... }
/// If declaration, this will be called on the partial result of an 'if
/// If declared, this will be called on the partial result of an 'if
/// #available' block to allow the function builder to erase type
/// information.
static func buildLimitedAvailability(_ component: Component) -> Component { ... }

0 comments on commit 25cd671

Please sign in to comment.
You can’t perform that action at this time.