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

Remove some duplicate code in VisualStudioProject

上级 d0ca0a22
......@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
......@@ -19,6 +20,7 @@ internal class SolutionChangeAccumulator
/// <see cref="WorkspaceChangeKind.SolutionChanged"/> if we can't give a more precise type.
/// </summary>
private WorkspaceChangeKind? _workspaceChangeKind;
private readonly List<DocumentId> _documentIdsRemoved = new List<DocumentId>();
public SolutionChangeAccumulator(Solution startingSolution)
{
......@@ -26,6 +28,7 @@ public SolutionChangeAccumulator(Solution startingSolution)
}
public Solution Solution { get; private set; }
public IEnumerable<DocumentId> DocumentIdsRemoved => _documentIdsRemoved;
public bool HasChange => _workspaceChangeKind.HasValue;
public WorkspaceChangeKind WorkspaceChangeKind => _workspaceChangeKind.Value;
......@@ -75,6 +78,17 @@ public void UpdateSolutionForDocumentAction(Solution newSolution, WorkspaceChang
}
}
/// <summary>
/// The same as <see cref="UpdateSolutionForDocumentAction(Solution, WorkspaceChangeKind, IEnumerable{DocumentId})" /> but also records
/// the removed documents into <see cref="DocumentIdsRemoved"/>.
/// </summary>
public void UpdateSolutionForRemovedDocumentAction(Solution solution, WorkspaceChangeKind removeDocumentChangeKind, IEnumerable<DocumentId> documentIdsRemoved)
{
UpdateSolutionForDocumentAction(solution, removeDocumentChangeKind, documentIdsRemoved);
_documentIdsRemoved.AddRange(documentIdsRemoved);
}
/// <summary>
/// Should be called to update the solution if there isn't a specific document change kind that should be
/// given to <see cref="UpdateSolutionForDocumentAction"/>
......
......@@ -422,17 +422,7 @@ private void OnBatchScopeDisposed()
documentsToOpen,
(s, documents) => s.AddDocuments(documents),
WorkspaceChangeKind.DocumentAdded,
(s, ids) =>
{
foreach (var id in ids)
{
// Clear any document-specific data now (like open file trackers, etc.). If we called OnRemoveDocument directly this is
// called, but since we're doing this in one large batch we need to do it now.
_workspace.ClearDocumentData(id);
}
return s.RemoveDocuments(ids);
},
(s, ids) => s.RemoveDocuments(ids),
WorkspaceChangeKind.DocumentRemoved);
_additionalFiles.UpdateSolutionForBatch(
......@@ -449,17 +439,7 @@ private void OnBatchScopeDisposed()
return s;
},
WorkspaceChangeKind.AdditionalDocumentAdded,
(s, ids) =>
{
foreach (var id in ids)
{
// Clear any document-specific data now (like open file trackers, etc.). If we called OnRemoveDocument directly this is
// called, but since we're doing this in one large batch we need to do it now.
_workspace.ClearDocumentData(id);
}
return s.RemoveAdditionalDocuments(ids);
},
(s, ids) => s.RemoveAdditionalDocuments(ids),
WorkspaceChangeKind.AdditionalDocumentRemoved);
_analyzerConfigFiles.UpdateSolutionForBatch(
......@@ -468,17 +448,7 @@ private void OnBatchScopeDisposed()
analyzerConfigDocumentsToOpen,
(s, documents) => s.AddAnalyzerConfigDocuments(documents),
WorkspaceChangeKind.AnalyzerConfigDocumentAdded,
(s, ids) =>
{
foreach (var id in ids)
{
// Clear any document-specific data now (like open file trackers, etc.). If we called OnRemoveAnalyzerConfigDocument directly this is
// called, but since we're doing this in one large batch we need to do it now.
_workspace.ClearDocumentData(id);
}
return s.RemoveAnalyzerConfigDocuments(ids);
},
(s, ids) => s.RemoveAnalyzerConfigDocuments(ids),
WorkspaceChangeKind.AnalyzerConfigDocumentRemoved);
// Metadata reference adding...
......@@ -1604,7 +1574,7 @@ public void ReorderFiles(ImmutableArray<string> filePaths)
ClearAndZeroCapacity(_documentsAddedInBatch);
// Document removing...
solutionChanges.UpdateSolutionForDocumentAction(removeDocuments(solutionChanges.Solution, _documentsRemovedInBatch.ToImmutableArray()),
solutionChanges.UpdateSolutionForRemovedDocumentAction(removeDocuments(solutionChanges.Solution, _documentsRemovedInBatch.ToImmutableArray()),
removeDocumentChangeKind,
_documentsRemovedInBatch);
......
......@@ -1496,6 +1496,11 @@ public void ApplyBatchChangeToWorkspace(Func<CodeAnalysis.Solution, SolutionChan
return;
}
foreach (var documentId in solutionChangeAccumulator.DocumentIdsRemoved)
{
this.ClearDocumentData(documentId);
}
SetCurrentSolution(solutionChangeAccumulator.Solution);
RaiseWorkspaceChangedEventAsync(
solutionChangeAccumulator.WorkspaceChangeKind,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册