From bfbfec3546735292d10b6d022ea78eaa763a5a7b Mon Sep 17 00:00:00 2001 From: David Poeschl Date: Tue, 4 Aug 2015 14:31:34 -0700 Subject: [PATCH] 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. --- .../Core/Impl/RoslynVisualStudioWorkspace.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs b/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs index 10ce8e9eba7..d7621476ee8 100644 --- a/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs +++ b/src/VisualStudio/Core/Impl/RoslynVisualStudioWorkspace.cs @@ -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(); - bool needsSave = globalUndoService.IsGlobalTransactionOpen(this); - bool needsUndoDisabled = needsSave && this.Services.GetService().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().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); } -- GitLab