diff --git a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs index ba199b28c4ad17e26ac5bde181893206493b95a0..c739a1f09c25cf007d10c5cda0a21360c63dc49d 100644 --- a/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs +++ b/src/VisualStudio/Core/Def/Implementation/ProjectSystem/VisualStudioProject.cs @@ -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.Builder documentFileNamesAdded, List<(DocumentId, SourceTextContainer)> documentsToOpen, - Func addDocument, + Func, Solution> addDocuments, Func 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); diff --git a/src/Workspaces/Core/Portable/Workspace/Workspace.cs b/src/Workspaces/Core/Portable/Workspace/Workspace.cs index 85d100475838d13856cbcf1615afef4f220ef863..7f025665bc253290f5de5b3b74868a2d90e06518 100644 --- a/src/Workspaces/Core/Portable/Workspace/Workspace.cs +++ b/src/Workspaces/Core/Portable/Workspace/Workspace.cs @@ -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. /// - protected virtual void ClearDocumentData(DocumentId documentId) + protected internal virtual void ClearDocumentData(DocumentId documentId) { this.ClearOpenDocument(documentId); }