提交 e33dbac4 编写于 作者: J Jason Malinowski

Fix handing of batch adding/removal of documents

Two bugs being fixed here:

1. When we remove a document in a non-batch scenario, we close any
   information related to the open document. If we were in a batch
   scenario, the SetCurrentSolution we do to apply the new Solution
   snapshot didn't go through that. Now we do.
2. UpdateSolutionForBatch wasn't calling the delegates given; this would
   have meant that additional files being added in a batch would have
   been added a regular source files.
上级 ff1e8f1c
......@@ -298,8 +298,37 @@ private void OnBatchScopeDisposed()
_workspace.ApplyBatchChangeToProject(Id, solution =>
{
solution = _sourceFiles.UpdateSolutionForBatch(solution, documentFileNamesAdded, documentsToOpen, (s, d) => s.AddDocument(d), (s, id) => s.RemoveDocument(id));
solution = _additionalFiles.UpdateSolutionForBatch(solution, documentFileNamesAdded, documentsToOpen, (s, d) => s.AddAdditionalDocument(d), (s, id) => s.RemoveAdditionalDocument(id));
solution = _sourceFiles.UpdateSolutionForBatch(
solution,
documentFileNamesAdded,
documentsToOpen,
(s, documents) => solution.AddDocuments(documents),
(s, id) =>
{
// Clear any document-specific data now (like open file trackers, etc.)
_workspace.ClearDocumentData(id);
return s.RemoveDocument(id);
});
solution = _additionalFiles.UpdateSolutionForBatch(
solution,
documentFileNamesAdded,
documentsToOpen,
(s, documents) =>
{
foreach (var document in documents)
{
s = s.AddAdditionalDocument(document);
}
return s;
},
(s, id) =>
{
// Clear any document-specific data now (like open file trackers, etc.)
_workspace.ClearDocumentData(id);
return s.RemoveAdditionalDocument(id);
});
// Metadata reference adding...
if (_metadataReferencesAddedInBatch.Count > 0)
......@@ -1083,11 +1112,11 @@ public void ProcessFileChange(string fullFilePath)
Solution solution,
ImmutableArray<string>.Builder documentFileNamesAdded,
List<(DocumentId, SourceTextContainer)> documentsToOpen,
Func<Solution, DocumentInfo, Solution> addDocument,
Func<Solution, ImmutableArray<DocumentInfo>, Solution> addDocuments,
Func<Solution, DocumentId, Solution> removeDocument)
{
// Document adding...
solution = solution.AddDocuments(_documentsAddedInBatch.ToImmutable());
solution = addDocuments(solution, _documentsAddedInBatch.ToImmutable());
foreach (var documentInfo in _documentsAddedInBatch)
{
......@@ -1104,7 +1133,7 @@ public void ProcessFileChange(string fullFilePath)
// Document removing...
foreach (var documentId in _documentsRemovedInBatch)
{
solution = solution.RemoveDocument(documentId);
solution = removeDocument(solution, documentId);
}
ClearAndZeroCapacity(_documentsRemovedInBatch);
......
......@@ -282,7 +282,7 @@ protected virtual void ClearProjectData(ProjectId projectId)
/// Override this method if you want to do additional work when a document is removed.
/// Call the base method at the end of your method.
/// </summary>
protected virtual void ClearDocumentData(DocumentId documentId)
protected internal virtual void ClearDocumentData(DocumentId documentId)
{
this.ClearOpenDocument(documentId);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册