mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user