Skip to content

[code-completion] Disable diagnostics in @functionBuilder bodies #25922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/swift/Basic/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class SourceManager {
rangeContainsTokenLoc(Enclosing, Inner.End);
}

/// Returns true if range \p R contains the code-completion location, if any.
bool rangeContainsCodeCompletionLoc(SourceRange R) const {
return CodeCompletionBufferID
? rangeContainsTokenLoc(R, getCodeCompletionLoc())
: false;
}

/// Returns the buffer ID for the specified *valid* location.
///
/// Because a valid source location always corresponds to a source buffer,
Expand Down
12 changes: 12 additions & 0 deletions lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ bool TypeChecker::typeCheckFunctionBuilderFuncBody(FuncDecl *FD,
options |= TypeCheckExprFlags::ConvertTypeIsOpaqueReturnType;
}

// If we are performing code-completion inside the functions body, supress
// diagnostics to workaround typechecking performance problems.
if (Context.SourceMgr.rangeContainsCodeCompletionLoc(
FD->getBody()->getSourceRange()))
options |= TypeCheckExprFlags::SuppressDiagnostics;

// Type-check the single result expression.
Type returnExprType = typeCheckExpression(returnExpr, FD,
TypeLoc::withoutLoc(returnType),
Expand Down Expand Up @@ -574,6 +580,12 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
assert(!builderType->hasTypeParameter());
}

// If we are performing code-completion inside the closure body, supress
// diagnostics to workaround typechecking performance problems.
if (getASTContext().SourceMgr.rangeContainsCodeCompletionLoc(
closure->getSourceRange()))
Options |= ConstraintSystemFlags::SuppressDiagnostics;

BuilderClosureVisitor visitor(getASTContext(), this,
/*wantExpr=*/true, builderType);
Expr *singleExpr = visitor.visit(closure->getBody());
Expand Down