提交 d54e0576 编写于 作者: J Jason Malinowski

Fix crash where we are not always finding text snapshots

Given this is not a reliable crash, my guess is the problem is we are
sometimes processing an older Solution snapshot. Asking a specific
SourceText for the specific ITextSnapshot it came from could fail
if that snapshot had been GC'ed, whereas going to the container
first and asking for the buffer directly should be more reliable. Either
way we now also handle the null case.

Fixes https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1010045
上级 3d5b94dc
......@@ -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."));
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册