diff --git a/src/EditorFeatures/Core/Implementation/Formatting/InferredIndentationDocumentOptionsProviderFactory.cs b/src/EditorFeatures/Core/Implementation/Formatting/InferredIndentationDocumentOptionsProviderFactory.cs index 6749ba5c6883ba0c7ddd7069f20b6e15e11c40d0..622747ef4f97496f82412e0780fe183ccccba00a 100644 --- a/src/EditorFeatures/Core/Implementation/Formatting/InferredIndentationDocumentOptionsProviderFactory.cs +++ b/src/EditorFeatures/Core/Implementation/Formatting/InferredIndentationDocumentOptionsProviderFactory.cs @@ -5,6 +5,7 @@ using System.ComponentModel.Composition; using System.Threading; using System.Threading.Tasks; +using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Text; @@ -71,8 +72,16 @@ public bool TryGetDocumentOption(OptionKey option, out object? value) var currentDocument = _workspace.CurrentSolution.GetDocument(_documentId); if (currentDocument != null && currentDocument.TryGetText(out var text)) { - var snapshot = text.FindCorrespondingEditorTextSnapshot(); - return TryGetOptionForBuffer(snapshot.TextBuffer, option, out value); + var textBuffer = text.Container.TryGetTextBuffer(); + + if (textBuffer != null) + { + return TryGetOptionForBuffer(textBuffer, option, out value); + } + else + { + FatalError.ReportWithoutCrash(new System.Exception("We had an open document but it wasn't associated with a buffer. That meant we coudln't apply formatting settings.")); + } } }