Skip to content

Bring back SourceManager::rangeContainsCodeCompletionLoc() #26976

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

Closed
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
5 changes: 1 addition & 4 deletions lib/Parse/ParseRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ BraceStmt *ParseAbstractFunctionBodyRequest::evaluate(
}

case BodyKind::Unparsed: {
// FIXME: It should be fine to delay body parsing of local functions, so
// the DelayBodyParsing should go away entirely
// FIXME: How do we configure code completion?
SourceFile &sf = *afd->getDeclContext()->getParentSourceFile();
SourceManager &sourceMgr = sf.getASTContext().SourceMgr;
unsigned bufferID = sourceMgr.findBufferContainingLoc(afd->getLoc());
Parser parser(bufferID, sf, nullptr, nullptr, nullptr,
/*DelayBodyParsing=*/false);
Parser parser(bufferID, sf, nullptr, nullptr, nullptr);
parser.SyntaxContext->setDiscard();
auto body = parser.parseAbstractFunctionBodyDelayed(afd);
afd->setBodyKind(BodyKind::Parsed);
Expand Down