Exemplo n.º 1
0
        protected async Task HandleStackTraceRequest(
            StackTraceRequestArguments stackTraceParams,
            RequestContext <StackTraceResponseBody> requestContext)
        {
            StackFrameDetails[] stackFrames =
                editorSession.DebugService.GetStackFrames();

            List <StackFrame> newStackFrames = new List <StackFrame>();

            for (int i = 0; i < stackFrames.Length; i++)
            {
                // Create the new StackFrame object with an ID that can
                // be referenced back to the current list of stack frames
                newStackFrames.Add(
                    StackFrame.Create(
                        stackFrames[i],
                        i));
            }

            await requestContext.SendResult(
                new StackTraceResponseBody
            {
                StackFrames = newStackFrames.ToArray()
            });
        }
        protected async Task HandleStackTraceRequestAsync(
            StackTraceRequestArguments stackTraceParams,
            RequestContext <StackTraceResponseBody> requestContext)
        {
            StackFrameDetails[] stackFrames =
                _editorSession.DebugService.GetStackFrames();

            // Handle a rare race condition where the adapter requests stack frames before they've
            // begun building.
            if (stackFrames == null)
            {
                await requestContext.SendResultAsync(
                    new StackTraceResponseBody
                {
                    StackFrames = new StackFrame[0],
                    TotalFrames = 0
                });

                return;
            }

            List <StackFrame> newStackFrames = new List <StackFrame>();

            int startFrameIndex = stackTraceParams.StartFrame ?? 0;
            int maxFrameCount   = stackFrames.Length;

            // If the number of requested levels == 0 (or null), that means get all stack frames
            // after the specified startFrame index. Otherwise get all the stack frames.
            int requestedFrameCount = (stackTraceParams.Levels ?? 0);

            if (requestedFrameCount > 0)
            {
                maxFrameCount = Math.Min(maxFrameCount, startFrameIndex + requestedFrameCount);
            }

            for (int i = startFrameIndex; i < maxFrameCount; i++)
            {
                // Create the new StackFrame object with an ID that can
                // be referenced back to the current list of stack frames
                newStackFrames.Add(
                    StackFrame.Create(
                        stackFrames[i],
                        i));
            }

            await requestContext.SendResultAsync(
                new StackTraceResponseBody
            {
                StackFrames = newStackFrames.ToArray(),
                TotalFrames = newStackFrames.Count
            });
        }