diff options
author | Jeffrey Stedfast <jestedfa@microsoft.com> | 2019-07-03 20:08:02 +0300 |
---|---|---|
committer | Jeffrey Stedfast <jestedfa@microsoft.com> | 2019-07-03 20:31:06 +0300 |
commit | 8e84ee7731e1ff8ec7cf5e21356451a19e34f913 (patch) | |
tree | c6e2031bfba588afd1d84de6d1d7722e5eb2a1f6 /main | |
parent | 9cbe4d88dcf23eceb17d2a929fb1628d505a749a (diff) |
[Debugger] Protect against NRE's in the CSharpBreakpointSpanResolver
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/935126/
Diffstat (limited to 'main')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.Debugger/CSharpBreakpointSpanResolver.cs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Debugger/CSharpBreakpointSpanResolver.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Debugger/CSharpBreakpointSpanResolver.cs index e3d57dcec6..be9699573f 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Debugger/CSharpBreakpointSpanResolver.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Debugger/CSharpBreakpointSpanResolver.cs @@ -47,11 +47,12 @@ namespace MonoDevelop.CSharp.Debugger public async Task<Span> GetBreakpointSpanAsync (ITextBuffer buffer, int position, CancellationToken cancellationToken) { - var document = buffer.AsTextContainer ().GetOpenDocumentInCurrentContext (); - var tree = await document.GetSyntaxTreeAsync (cancellationToken); + var document = buffer.AsTextContainer ()?.GetOpenDocumentInCurrentContext (); + var tree = document != null ? await document.GetSyntaxTreeAsync (cancellationToken) : null; - if (BreakpointSpans.TryGetBreakpointSpan (tree, Math.Max (0, Math.Min (position, tree.Length - 1)), cancellationToken, out var span)) + if (tree != null && BreakpointSpans.TryGetBreakpointSpan (tree, Math.Max (0, Math.Min (position, tree.Length - 1)), cancellationToken, out var span)) return new Span (span.Start, span.Length); + return buffer.CurrentSnapshot.GetLineFromPosition (Math.Max (0, Math.Min (position, buffer.CurrentSnapshot.Length - 1))).Extent.Span; } } |