@@ -6726,6 +6726,20 @@ void AbstractFunctionDecl::setBody(BraceStmt *S, BodyKind NewBodyKind) {
67266726 }
67276727}
67286728
6729+ void AbstractFunctionDecl::setBodyToBeReparsed (SourceRange bodyRange) {
6730+ assert (bodyRange.isValid ());
6731+ assert (getBodyKind () == BodyKind::Unparsed ||
6732+ getBodyKind () == BodyKind::Parsed ||
6733+ getBodyKind () == BodyKind::TypeChecked);
6734+ assert (getASTContext ().SourceMgr .rangeContainsTokenLoc (
6735+ bodyRange, getASTContext ().SourceMgr .getCodeCompletionLoc ()) &&
6736+ " This function is only intended to be used for code completion" );
6737+
6738+ keepOriginalBodySourceRange ();
6739+ BodyRange = bodyRange;
6740+ setBodyKind (BodyKind::Unparsed);
6741+ }
6742+
67296743SourceRange AbstractFunctionDecl::getBodySourceRange () const {
67306744 switch (getBodyKind ()) {
67316745 case BodyKind::None:
@@ -7386,7 +7400,7 @@ SourceRange FuncDecl::getSourceRange() const {
73867400 getBodyKind () == BodyKind::Skipped)
73877401 return { StartLoc, BodyRange.End };
73887402
7389- SourceLoc RBraceLoc = getBodySourceRange ().End ;
7403+ SourceLoc RBraceLoc = getOriginalBodySourceRange ().End ;
73907404 if (RBraceLoc.isValid ()) {
73917405 return { StartLoc, RBraceLoc };
73927406 }
@@ -7507,7 +7521,7 @@ SourceRange ConstructorDecl::getSourceRange() const {
75077521 if (isImplicit ())
75087522 return getConstructorLoc ();
75097523
7510- SourceLoc End = getBodySourceRange ().End ;
7524+ SourceLoc End = getOriginalBodySourceRange ().End ;
75117525 if (End.isInvalid ())
75127526 End = getGenericTrailingWhereClauseSourceRange ().End ;
75137527 if (End.isInvalid ())
@@ -7733,7 +7747,7 @@ ConstructorDecl::getDelegatingOrChainedInitKind(DiagnosticEngine *diags,
77337747}
77347748
77357749SourceRange DestructorDecl::getSourceRange () const {
7736- SourceLoc End = getBodySourceRange ().End ;
7750+ SourceLoc End = getOriginalBodySourceRange ().End ;
77377751 if (End.isInvalid ()) {
77387752 End = getDestructorLoc ();
77397753 }
0 commit comments