提交 5f551ec7 编写于 作者: C Cheryl Borley 提交者: Jinu

Add null check for textSnapshot (#24693)

* Add null check for textSnapshot

Fixes #7364

* Respond to feedback

Changed from return to continue and added a non fatal exception

* respond to feedback

Moved NullTextBufferException to InlineRenameSession and added SourceText.
上级 53204961
......@@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Editor.Undo;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Options;
......@@ -153,6 +154,20 @@ private void OnBeforeDebuggingStateChanged(object sender, DebuggingStateChangedE
public string OriginalSymbolName => _renameInfo.DisplayName;
// Used to aid the investigation of https://github.com/dotnet/roslyn/issues/7364
private class NullTextBufferException : Exception
{
private readonly Document _document;
private readonly SourceText _text;
public NullTextBufferException(Document document, SourceText text)
: base("Cannot retrieve textbuffer from document.")
{
_document = document;
_text = text;
}
}
private void InitializeOpenBuffers(SnapshotSpan triggerSpan)
{
using (Logger.LogBlock(FunctionId.Rename_CreateOpenTextBufferManagerForAllOpenDocs, CancellationToken.None))
......@@ -165,7 +180,11 @@ private void InitializeOpenBuffers(SnapshotSpan triggerSpan)
Contract.ThrowIfNull(text);
var textSnapshot = text.FindCorrespondingEditorTextSnapshot();
Contract.ThrowIfNull(textSnapshot);
if (textSnapshot == null)
{
FatalError.ReportWithoutCrash(new NullTextBufferException(document, text));
continue;
}
Contract.ThrowIfNull(textSnapshot.TextBuffer);
openBuffers.Add(textSnapshot.TextBuffer);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册