Skip to content

Commit 25cd671

Browse files
committed
[Code completion] Test and fix 'static func' for function builder methods.
1 parent 23b6b40 commit 25cd671

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5316,7 +5316,7 @@ NOTE(function_builder_missing_build_optional, none,
53165316
"add 'buildOptional(_:)' to the function builder %0 to add support for "
53175317
"'if' statements without an 'else'", (Type))
53185318
NOTE(function_builder_missing_build_either, none,
5319-
"add 'buildEither(first:)' and `buildEither(second:)' to the function "
5319+
"add 'buildEither(first:)' and 'buildEither(second:)' to the function "
53205320
"builder %0 to add support for 'if'-'else' and 'switch'", (Type))
53215321
NOTE(function_builder_missing_build_array, none,
53225322
"add 'buildArray(_:)' to the function builder %0 to add support for "

lib/IDE/CodeCompletion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5170,7 +5170,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
51705170
"outermost block statement to produce the final returned result";
51715171

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

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

51975197
if (!hasStaticOrClass)
5198-
Builder.addKeyword("static");
5198+
Builder.addTextChunk("static ");
51995199

5200-
Builder.addKeyword("func");
5200+
Builder.addTextChunk("func ");
52015201
}
52025202

52035203
std::string declStringWithoutFunc;

test/Constraints/function_builder_diags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct TupleBuilder { // expected-note 2 {{struct 'TupleBuilder' declared here}}
4747
@_functionBuilder
4848
struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf' declared here}}
4949
// 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 \}}}
50-
// 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 \}}}
50+
// 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 \}}}
5151
// 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 \}}}
5252
static func buildBlock() -> () { }
5353

test/IDE/complete_function_builder.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_CLOSURE_NONTOP | %FileCheck %s -check-prefix=IN_CLOSURE_TOP
33
// 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
44
// 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
5+
// 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
56

67
struct Tagged<Tag, Entity> {
78
let tag: Tag
@@ -99,6 +100,8 @@ func acceptBuilder(@EnumToVoidBuilder body: () -> Void) {}
99100
struct AnyBuilder {
100101
static func buildBlock(_ components: Any...) -> Any { 5 }
101102

103+
#^IN_FUNCTION_BUILDER_DECL_PREFIX^#
104+
102105
static func #^IN_FUNCTION_BUILDER_DECL^#
103106
}
104107

@@ -112,3 +115,14 @@ struct AnyBuilder {
112115
// IN_FUNCTION_BUILDER_DECL: Pattern/CurrNominal: buildLimitedAvailability(_ component: Any) -> Any {|}; name=buildLimitedAvailability(_ component: Any) -> Any; comment=
113116
// IN_FUNCTION_BUILDER_DECL: Pattern/CurrNominal: buildFinalResult(_ component: Any) -> <#Result#> {|}; name=buildFinalResult(_ component: Any) -> <#Result#>; comment=
114117
// IN_FUNCTION_BUILDER_DECL: End completions
118+
119+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Begin completions
120+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildBlock(_ components: Any...) -> Any {|}; name=static func buildBlock(_ components: Any...) -> Any; comment=Required by every
121+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildExpression(_ expression: <#Expression#>) -> Any {|}; name=static func buildExpression(_ expression: <#Expression#>) -> Any; comment=
122+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildOptional(_ component: Any?) -> Any {|}; name=static func buildOptional(_ component: Any?) -> Any; comment=
123+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildEither(first component: Any) -> Any {|}; name=static func buildEither(first component: Any) -> Any; comment=
124+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildEither(second component: Any) -> Any {|}; name=static func buildEither(second component: Any) -> Any; comment=
125+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildArray(_ components: [Any]) -> Any {|}; name=static func buildArray(_ components: [Any]) -> Any; comment=
126+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildLimitedAvailability(_ component: Any) -> Any {|}; name=static func buildLimitedAvailability(_ component: Any) -> Any; comment=
127+
// IN_FUNCTION_BUILDER_DECL_PREFIX: Pattern/CurrNominal: static func buildFinalResult(_ component: Any) -> <#Result#> {|}; name=static func buildFinalResult(_ component: Any) -> <#Result#>; comment=
128+
// IN_FUNCTION_BUILDER_DECL_PREFIX: End completions

userdocs/diagnostics/function-builder-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct ExampleFunctionBuilder {
4444
/// results of all iterations into a single result.
4545
static func buildArray(_ components: [Component]) -> Component { ... }
4646

47-
/// If declaration, this will be called on the partial result of an 'if
47+
/// If declared, this will be called on the partial result of an 'if
4848
/// #available' block to allow the function builder to erase type
4949
/// information.
5050
static func buildLimitedAvailability(_ component: Component) -> Component { ... }

0 commit comments

Comments
 (0)