提交 bfbfec35 编写于 作者: D David Poeschl

Allow CodeFixes to edit closed AdditionalDocuments under global undo transactions

Fixes #3967

Update RoslynVisualStudioWorkspace.OpenInvisibleEditor to remove the assumption that Solution.GetDocument(DocumentId) will always work for a given IVisualStudioHostDocument's ID. GetDocument returns null on all AdditionalDocuments, causing the eventual reported NullReferenceException.
上级 ad621a70
......@@ -124,8 +124,22 @@ internal override IInvisibleEditor OpenInvisibleEditor(IVisualStudioHostDocument
{
// We need to ensure the file is saved, only if a global undo transaction is open
var globalUndoService = this.Services.GetService<IGlobalUndoService>();
bool needsSave = globalUndoService.IsGlobalTransactionOpen(this);
bool needsUndoDisabled = needsSave && this.Services.GetService<IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id));
var needsSave = globalUndoService.IsGlobalTransactionOpen(this);
var needsUndoDisabled = false;
if (needsSave)
{
if (this.CurrentSolution.ContainsDocument(hostDocument.Id))
{
// Disable undo on generated documents
needsUndoDisabled = this.Services.GetService<IGeneratedCodeRecognitionService>().IsGeneratedCode(this.CurrentSolution.GetDocument(hostDocument.Id));
}
else
{
// Enable undo on "additional documents" or if no document can be found.
needsUndoDisabled = false;
}
}
return new InvisibleEditor(ServiceProvider, hostDocument.FilePath, needsSave, needsUndoDisabled);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册