diff --git a/src/Workspaces/Core/Portable/Workspace/TextExtensions.cs b/src/Workspaces/Core/Portable/Workspace/TextExtensions.cs index 61500749daee4..ee583cb1ee2fa 100644 --- a/src/Workspaces/Core/Portable/Workspace/TextExtensions.cs +++ b/src/Workspaces/Core/Portable/Workspace/TextExtensions.cs @@ -33,14 +33,15 @@ public static Document GetOpenDocumentInCurrentContextWithChanges(this SourceTex { if (Workspace.TryGetWorkspace(text.Container, out var workspace)) { + var solution = workspace.CurrentSolution; var id = workspace.GetDocumentIdInCurrentContext(text.Container); - if (id == null || !workspace.CurrentSolution.ContainsDocument(id)) + if (id == null || !solution.ContainsDocument(id)) { return null; } - var sol = workspace.CurrentSolution.WithDocumentText(id, text, PreservationMode.PreserveIdentity); - return sol.GetDocument(id); + return solution.WithDocumentText(id, text, PreservationMode.PreserveIdentity) + .GetDocument(id); } return null;