[SourceKit] Fix a crash that occurred when a document without an associated source file is reopened

When opening a file for the first time, we don’t store a snapshot for it. This could cause a crash when trying to consult its snapshot to see whether an AST can be reused for cursor info.
This commit is contained in:
Alex Hoppen
2021-12-10 16:44:10 +01:00
parent 5a6341bd65
commit f5b6103ef7
2 changed files with 26 additions and 1 deletions

View File

@@ -1185,7 +1185,9 @@ ASTBuildOperationRef ASTProducer::getBuildOperationForConsumer(
std::vector<ImmutableTextSnapshotRef> Snapshots;
Snapshots.reserve(BuildOp->getFileContents().size());
for (auto &FileContent : BuildOp->getFileContents()) {
Snapshots.push_back(FileContent.Snapshot);
if (FileContent.Snapshot) {
Snapshots.push_back(FileContent.Snapshot);
}
}
if (BuildOp->matchesSourceState(FileSystem)) {
++Mgr->Impl.Stats->numASTCacheHits;