@@ -959,8 +959,8 @@ class ResultBuilderTransform
959959 VarDecl *captureExpr (Expr *expr, SmallVectorImpl<ASTNode> &container) {
960960 auto *var = builder.buildVar (expr->getStartLoc ());
961961 Pattern *pattern = NamedPattern::createImplicit (ctx, var);
962- auto *PB = PatternBindingDecl::createImplicit (ctx, StaticSpellingKind::None,
963- pattern, expr, dc);
962+ auto *PB = PatternBindingDecl::createImplicit (
963+ ctx, StaticSpellingKind::None, pattern, expr, dc, var-> getStartLoc () );
964964 return recordVar (PB, container);
965965 }
966966
@@ -972,7 +972,8 @@ class ResultBuilderTransform
972972 ctx, NamedPattern::createImplicit (ctx, var),
973973 type ? type : PlaceholderType::get (ctx, var));
974974 auto *PB = PatternBindingDecl::createImplicit (
975- ctx, StaticSpellingKind::None, placeholder, /* init=*/ initExpr, dc);
975+ ctx, StaticSpellingKind::None, placeholder, /* init=*/ initExpr, dc,
976+ var->getStartLoc ());
976977 return recordVar (PB, container);
977978 }
978979
@@ -1058,11 +1059,20 @@ class ResultBuilderTransform
10581059 {Identifier ()});
10591060 }
10601061
1061- auto *capture = captureExpr (expr, newBody);
1062- // A reference to the synthesized variable is passed as an argument
1063- // to buildBlock.
1064- buildBlockArguments.push_back (
1065- builder.buildVarRef (capture, element.getStartLoc ()));
1062+ if (isa<CodeCompletionExpr>(expr)) {
1063+ // Insert the CodeCompletionExpr directly into the buildBlock call. That
1064+ // way, we can extract the contextual type of the code completion token
1065+ // to rank code completion items that match the type expected by
1066+ // buildBlock higher.
1067+ buildBlockArguments.push_back (expr);
1068+ } else {
1069+ auto *capture = captureExpr (expr, newBody);
1070+ // A reference to the synthesized variable is passed as an argument
1071+ // to buildBlock.
1072+ buildBlockArguments.push_back (
1073+ builder.buildVarRef (capture, element.getStartLoc ()));
1074+ }
1075+
10661076 return None;
10671077 }
10681078
@@ -2459,7 +2469,9 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
24592469 return None;
24602470 }
24612471
2462- if (Context.LangOpts .hasFeature (Feature::ResultBuilderASTTransform)) {
2472+ auto disableASTTransform = [&](NominalTypeDecl *builder) { return false ; };
2473+
2474+ if (!disableASTTransform (builder)) {
24632475 auto transformedBody = getBuilderTransformedBody (fn, builder);
24642476 // If this builder transform has not yet been applied to this function,
24652477 // let's do it and cache the result.
@@ -2517,7 +2529,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
25172529 auto &log = llvm::errs ();
25182530 auto indent = solverState ? solverState->getCurrentIndent () : 0 ;
25192531 log.indent (indent) << " ------- Transfomed Body -------\n " ;
2520- transformedBody->second ->dump (log);
2532+ transformedBody->second ->dump (log, & getASTContext (), indent );
25212533 log << ' \n ' ;
25222534 }
25232535
0 commit comments