File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -1030,6 +1030,23 @@ class SyntacticElementConstraintGenerator
10301030
10311031 SmallVector<ElementInfo, 4 > elements;
10321032 for (auto element : braceStmt->getElements ()) {
1033+ if (cs.isForCodeCompletion () &&
1034+ !cs.containsIDEInspectionTarget (element)) {
1035+ // Statements and expressions can't influence the expresion that
1036+ // contains the code completion token. To improve performance, skip
1037+ // type checking them entirely.
1038+ if (element.is <Expr *>() && !element.isExpr (ExprKind::TypeJoin)) {
1039+ // Type join expressions are not really pure expressions, they kind of
1040+ // declare new type variables and are important to a result builder's
1041+ // structure. Don't skip them.
1042+ continue ;
1043+ } else if (element.is <Stmt *>() && !element.isStmt (StmtKind::Guard)) {
1044+ // Guard statements might define variables that are used in the code
1045+ // completion expression. Don't skip them.
1046+ continue ;
1047+ }
1048+ }
1049+
10331050 if (auto *decl = element.dyn_cast <Decl *>()) {
10341051 if (auto *PDB = dyn_cast<PatternBindingDecl>(decl)) {
10351052 visitPatternBinding (PDB, elements);
Original file line number Diff line number Diff line change @@ -274,3 +274,31 @@ func testAmbiguousInResultBuilder() {
274274// AMBIGUOUS_IN_RESULT_BUILDER: End completions
275275 }
276276}
277+
278+ func testCompleteGlobalInResultBuilderIf( ) {
279+ func buildView( @ViewBuilder2 content: ( ) -> MyView ) { }
280+
281+ @resultBuilder public struct ViewBuilder2 {
282+ static func buildBlock( ) -> MyView { fatalError ( ) }
283+ static func buildBlock( _ content: MyView ) -> MyView { fatalError ( ) }
284+ static func buildIf( _ content: MyView ? ) -> MyView ? { fatalError ( ) }
285+ static func buildEither( first: MyView ) -> MyView { fatalError ( ) }
286+ static func buildEither( second: MyView ) -> MyView { fatalError ( ) }
287+ }
288+
289+ struct MyView { }
290+
291+ func test( ) {
292+ buildView {
293+ if true {
294+ MyView ( )
295+ } else {
296+ #^GLOBAL_IN_RESULT_BUILDER_IF^#
297+ }
298+ }
299+ }
300+
301+ // GLOBAL_IN_RESULT_BUILDER_IF: Begin completions
302+ // GLOBAL_IN_RESULT_BUILDER_IF-DAG: Decl[Struct]/Local/TypeRelation[Convertible]: MyView[#MyView#]; name=MyView
303+ // GLOBAL_IN_RESULT_BUILDER_IF: End completions
304+ }
You can’t perform that action at this time.
0 commit comments