提交 f532373b 编写于 作者: K Kevin Pilch-Bisson 提交者: GitHub

Merge pull request #12308 from Pilchie/unload-with-open-documents

Unload with open documents
......@@ -365,10 +365,9 @@ public void TestRemoveProjectWithOpenedDocuments()
workspace.AddTestProject(project1);
workspace.OnDocumentOpened(document.Id, document.GetOpenTextContainer());
Assert.Throws<ArgumentException>(() => workspace.OnProjectRemoved(project1.Id));
workspace.OnDocumentClosed(document.Id);
workspace.OnProjectRemoved(project1.Id);
Assert.False(workspace.IsDocumentOpen(document.Id));
Assert.Empty(workspace.CurrentSolution.Projects);
}
}
......
......@@ -350,6 +350,8 @@ private void DetachFromDocument(uint docCookie, string moniker)
_hostProjects.Remove(hostProject.Id);
_docCookiesToHostProject.Remove(docCookie);
document.Dispose();
return;
}
}
......
......@@ -877,10 +877,11 @@ internal void UpdateDocumentContextIfContainsDocument(IVsHierarchy sharedHierarc
// find that one, we can map back to the open buffer and set its active context to
// the appropriate project.
// Note that if there is a single head project and it's in the process of being unloaded
// there might not be a host project.
var hostProject = LinkedFileUtilities.GetContextHostProject(sharedHierarchy, ProjectTracker);
if (hostProject.Hierarchy == sharedHierarchy)
if (hostProject?.Hierarchy == sharedHierarchy)
{
// How?
return;
}
......
......@@ -425,9 +425,12 @@ protected internal virtual void OnProjectRemoved(ProjectId projectId)
}
}
/// <summary>
/// Currently projects can always be removed, but this method still exists because it's protected and we don't
/// want to break people who may have derived from <see cref="Workspace"/> and either called it, or overridden it.
/// </summary>
protected virtual void CheckProjectCanBeRemoved(ProjectId projectId)
{
CheckProjectDoesNotContainOpenDocuments(projectId);
}
/// <summary>
......
......@@ -75,7 +75,9 @@ private void ClearOpenDocuments(ProjectId projectId)
if (openDocs != null)
{
foreach (var docId in openDocs)
// ClearOpenDocument will remove the document from the original set.
var copyOfOpenDocs = openDocs.ToList();
foreach (var docId in copyOfOpenDocs)
{
this.ClearOpenDocument(docId);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册