示例#1
0
        public async Task <Span> GetBreakpointSpanAsync(ITextBuffer buffer, int position, CancellationToken cancellationToken)
        {
            var document = buffer.AsTextContainer().GetOpenDocumentInCurrentContext();
            var tree     = await document.GetSyntaxTreeAsync(cancellationToken);

            BreakpointSpans.TryGetBreakpointSpan(tree, position, cancellationToken, out var span);

            return(new Span(span.Start, span.Length));
        }
示例#2
0
        public async Task <Span> GetBreakpointSpanAsync(ITextBuffer buffer, int position, CancellationToken cancellationToken)
        {
            var document = buffer.AsTextContainer()?.GetOpenDocumentInCurrentContext();
            var tree     = document != null ? await document.GetSyntaxTreeAsync(cancellationToken) : null;

            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);
        }
示例#3
0
 public static bool TryGetBreakpointSpan(
     SyntaxTree tree,
     int position,
     CancellationToken cancellationToken,
     out TextSpan breakpointSpan
     ) =>
 BreakpointSpans.TryGetBreakpointSpan(
     tree,
     position,
     cancellationToken,
     out breakpointSpan
     );
        internal static async Task <BreakpointResolutionResult> GetBreakpointAsync(Document document, int position, CancellationToken cancellationToken)
        {
            var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

            if (!BreakpointSpans.TryGetBreakpointSpan(tree, position, cancellationToken, out var span))
            {
                return(null);
            }

            if (span.Length == 0)
            {
                return(BreakpointResolutionResult.CreateLineResult(document));
            }

            return(BreakpointResolutionResult.CreateSpanResult(document, span));
        }
示例#5
0
        /// <summary>
        /// Returns null if a breakpoint can't be placed at the specified position.
        /// </summary>
        public async Task <BreakpointResolutionResult?> ResolveBreakpointAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
        {
            try
            {
                var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

                if (tree == null || !BreakpointSpans.TryGetBreakpointSpan(tree, textSpan.Start, cancellationToken, out var span))
                {
                    return(null);
                }

                if (span.Length == 0)
                {
                    return(BreakpointResolutionResult.CreateLineResult(document));
                }

                return(BreakpointResolutionResult.CreateSpanResult(document, span));
            }
            catch (Exception e) when(FatalError.ReportAndCatchUnlessCanceled(e, cancellationToken))
            {
                return(null);
            }
        }