Exemple #1
0
        public async Task <IReadOnlyList <DebugEvaluationResult> > GetChildrenAsync(
            DebugEvaluationResultFields fields,
            int?maxLength     = null,
            int?reprMaxLength = null,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            await TaskUtilities.SwitchToBackgroundThread();

            if (StackFrame == null)
            {
                throw new InvalidOperationException("Cannot retrieve children of an evaluation result that is not tied to a frame.");
            }
            if (Expression == null)
            {
                throw new InvalidOperationException("Cannot retrieve children of an evaluation result that does not have an associated expression.");
            }

            var call      = Invariant($@"rtvs:::toJSON(rtvs:::describe_children(
                {Expression.ToRStringLiteral()}, {StackFrame.SysFrame}, 
                {fields.ToRVector()}, {maxLength}, {reprMaxLength}))");
            var jChildren = await StackFrame.Session.InvokeDebugHelperAsync <JArray>(call, cancellationToken);

            Trace.Assert(
                jChildren.Children().All(t => t is JObject),
                Invariant($"rtvs:::describe_children(): object of objects expected.\n\n{jChildren}"));

            var children = new List <DebugEvaluationResult>();

            foreach (var child in jChildren)
            {
                var childObject = (JObject)child;
                Trace.Assert(
                    childObject.Count == 1,
                    Invariant($"rtvs:::describe_children(): each object is expected contain one object\n\n"));
                foreach (var kv in childObject)
                {
                    var name        = kv.Key;
                    var jEvalResult = (JObject)kv.Value;
                    var evalResult  = Parse(StackFrame, name, jEvalResult);
                    children.Add(evalResult);
                }
            }

            return(children);
        }
Exemple #2
0
        public async Task <DebugEvaluationResult> EvaluateAsync(
            DebugStackFrame stackFrame,
            string expression,
            string name,
            string env,
            DebugEvaluationResultFields fields,
            int?reprMaxLength = null,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            ThrowIfDisposed();

            await TaskUtilities.SwitchToBackgroundThread();

            await InitializeAsync(cancellationToken);

            env = env ?? stackFrame?.SysFrame ?? "NULL";
            var code        = Invariant($"rtvs:::toJSON(rtvs:::eval_and_describe({expression.ToRStringLiteral()}, {env},, {fields.ToRVector()},, {reprMaxLength}))");
            var jEvalResult = await InvokeDebugHelperAsync <JObject>(code, cancellationToken);

            return(DebugEvaluationResult.Parse(stackFrame, name, jEvalResult));
        }
        public async Task<IReadOnlyList<DebugEvaluationResult>> GetChildrenAsync(
            DebugEvaluationResultFields fields = DebugEvaluationResultFields.All,
            int? maxLength = null,
            int? reprMaxLength = null,
            CancellationToken cancellationToken = default(CancellationToken)
        ) {
            await TaskUtilities.SwitchToBackgroundThread();

            if (StackFrame == null) {
                throw new InvalidOperationException("Cannot retrieve children of an evaluation result that is not tied to a frame.");
            }
            if (Expression == null) {
                throw new InvalidOperationException("Cannot retrieve children of an evaluation result that does not have an associated expression.");
            }

            var call = Invariant($@"rtvs:::toJSON(rtvs:::describe_children(
                {Expression.ToRStringLiteral()}, {StackFrame.SysFrame}, 
                {fields.ToRVector()}, {maxLength}, {reprMaxLength}))");
            var jChildren = await StackFrame.Session.InvokeDebugHelperAsync<JArray>(call, cancellationToken);
            Trace.Assert(
                jChildren.Children().All(t => t is JObject),
                Invariant($"rtvs:::describe_children(): object of objects expected.\n\n{jChildren}"));

            var children = new List<DebugEvaluationResult>();
            foreach (var child in jChildren) {
                var childObject = (JObject)child;
                Trace.Assert(
                    childObject.Count == 1,
                    Invariant($"rtvs:::describe_children(): each object is expected contain one object\n\n"));
                foreach (var kv in childObject) {
                    var name = kv.Key;
                    var jEvalResult = (JObject)kv.Value;
                    var evalResult = Parse(StackFrame, name, jEvalResult);
                    children.Add(evalResult);
                }
            }

            return children;
        }