未验证 提交 d4743d78 编写于 作者: I Ivan Basov 提交者: GitHub

Fix for ValidateBreakpointLocationWorker NFW

上级 8db96423
......@@ -159,10 +159,17 @@ public void TryGetPositionTest()
}
[Fact]
public void GetPointTest()
public void TryGetPointValueTest()
{
var snapshot = GetSampleCodeSnapshot();
Assert.Equal(new SnapshotPoint(snapshot, 15), snapshot.GetPoint(3, 0));
Assert.Equal(new SnapshotPoint(snapshot, 15), snapshot.TryGetPoint(3, 0).Value);
}
[Fact]
public void TryGetPointNullTest()
{
var snapshot = GetSampleCodeSnapshot();
Assert.Null(snapshot.TryGetPoint(3000, 0));
}
[Fact]
......
......@@ -11,8 +11,18 @@ internal static partial class ITextSnapshotExtensions
public static SnapshotPoint GetPoint(this ITextSnapshot snapshot, int position)
=> new SnapshotPoint(snapshot, position);
public static SnapshotPoint GetPoint(this ITextSnapshot snapshot, int lineNumber, int columnIndex)
=> new SnapshotPoint(snapshot, snapshot.GetPosition(lineNumber, columnIndex));
public static SnapshotPoint? TryGetPoint(this ITextSnapshot snapshot, int lineNumber, int columnIndex)
{
var position = snapshot.TryGetPosition(lineNumber, columnIndex);
if (position.HasValue)
{
return new SnapshotPoint(snapshot, position.Value);
}
else
{
return null;
}
}
/// <summary>
/// Convert a <see cref="LinePositionSpan"/> to <see cref="TextSpan"/>.
......
......@@ -92,21 +92,25 @@ public int GetNameOfLocation(IVsTextBuffer pBuffer, int iLine, int iCol, out str
var textBuffer = _languageService.EditorAdaptersFactoryService.GetDataBuffer(pBuffer);
if (textBuffer != null)
{
var point = textBuffer.CurrentSnapshot.GetPoint(iLine, iCol);
var document = point.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
var nullablePoint = textBuffer.CurrentSnapshot.TryGetPoint(iLine, iCol);
if (nullablePoint.HasValue)
{
// NOTE(cyrusn): We have to wait here because the debuggers'
// GetNameOfLocation is a blocking call. In the future, it
// would be nice if they could make it async.
var debugLocationInfo = _languageDebugInfo.GetLocationInfoAsync(document, point, cancellationToken).WaitAndGetResult(cancellationToken);
var point = nullablePoint.Value;
var document = point.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (!debugLocationInfo.IsDefault)
if (document != null)
{
succeeded = true;
name = debugLocationInfo.Name;
lineOffset = debugLocationInfo.LineOffset;
// NOTE(cyrusn): We have to wait here because the debuggers'
// GetNameOfLocation is a blocking call. In the future, it
// would be nice if they could make it async.
var debugLocationInfo = _languageDebugInfo.GetLocationInfoAsync(document, point, cancellationToken).WaitAndGetResult(cancellationToken);
if (!debugLocationInfo.IsDefault)
{
succeeded = true;
name = debugLocationInfo.Name;
lineOffset = debugLocationInfo.LineOffset;
}
}
}
}
......@@ -146,16 +150,20 @@ public int GetProximityExpressions(IVsTextBuffer pBuffer, int iLine, int iCol, i
if (textBuffer != null)
{
var snapshot = textBuffer.CurrentSnapshot;
Document document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
var nullablePoint = snapshot.TryGetPoint(iLine, iCol);
if (nullablePoint.HasValue)
{
var point = snapshot.GetPoint(iLine, iCol);
var proximityExpressions = _proximityExpressionsService.GetProximityExpressionsAsync(document, point.Position, waitContext.CancellationToken).WaitAndGetResult(waitContext.CancellationToken);
if (proximityExpressions != null)
Document document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document != null)
{
enumBSTR = new VsEnumBSTR(proximityExpressions);
succeeded = true;
var point = nullablePoint.Value;
var proximityExpressions = _proximityExpressionsService.GetProximityExpressionsAsync(document, point.Position, waitContext.CancellationToken).WaitAndGetResult(waitContext.CancellationToken);
if (proximityExpressions != null)
{
enumBSTR = new VsEnumBSTR(proximityExpressions);
succeeded = true;
}
}
}
}
......@@ -278,10 +286,17 @@ public int ValidateBreakpointLocation(IVsTextBuffer pBuffer, int iLine, int iCol
if (textBuffer != null)
{
var snapshot = textBuffer.CurrentSnapshot;
var nullablePoint = snapshot.TryGetPoint(iLine, iCol);
if (nullablePoint == null)
{
// The point disappeared between sessions. Do not allow a breakpoint here.
return VSConstants.E_FAIL;
}
Document document = snapshot.AsText().GetDocumentWithFrozenPartialSemantics(cancellationToken);
if (document != null)
{
var point = snapshot.GetPoint(iLine, iCol);
var point = nullablePoint.Value;
var length = 0;
if (pCodeSpan != null && pCodeSpan.Length > 0)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册