Beispiel #1
0
 /// <summary>
 /// Like <see cref="TryEvaluateAndDescribeAsync(IRSession, string, string, string, REvaluationResultProperties, string, CancellationToken)"/>,
 /// but evaluates in the global environment (<c>.GlobalEnv</c>), and the result is not named.
 /// </summary>
 public static Task <IREvaluationResultInfo> TryEvaluateAndDescribeAsync(
     this IRSession session,
     string expression,
     REvaluationResultProperties properties,
     string repr,
     CancellationToken cancellationToken = default(CancellationToken)
     ) =>
 session.TryEvaluateAndDescribeAsync(REnvironments.GlobalEnv, expression, null, properties, repr, cancellationToken);
        private async Task EvaluateAsync()
        {
            try {
                await TaskUtilities.SwitchToBackgroundThread();

                const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty;

                var result = await _rSession.TryEvaluateAndDescribeAsync(_evaluation.Expression, properties, null);

                var wrapper = new VariableViewModel(result, _aggregator);

                VsAppShell.Current.DispatchOnUIThread(() => SetEvaluation(wrapper));
            } catch (Exception ex) {
                VsAppShell.Current.DispatchOnUIThread(() => SetError(ex.Message));
            }
        }
        private async Task EvaluateAsync()
        {
            try {
                await TaskUtilities.SwitchToBackgroundThread();

                const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty;

                var result = await _rSession.TryEvaluateAndDescribeAsync(_evaluation.Expression, properties, null);

                var wrapper = new VariableViewModel(result, _services);

                _services.MainThread().Post(() => SetEvaluation(wrapper));
            } catch (Exception ex) {
                _services.MainThread().Post(() => SetError(ex.Message));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Like <see cref="TryEvaluateAndDescribeAsync(IRSession, string, string, string, REvaluationResultProperties, string, CancellationToken)"/>,
        /// but throws <see cref="RException"/> if result is an <see cref="IRErrorInfo"/>.
        /// </summary>
        public static async Task <IRValueInfo> EvaluateAndDescribeAsync(
            this IRSession session,
            string environmentExpression,
            string expression,
            string name,
            REvaluationResultProperties properties,
            string repr,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            var info = await session.TryEvaluateAndDescribeAsync(environmentExpression, expression, name, properties, repr, cancellationToken);

            var error = info as IRErrorInfo;

            if (error != null)
            {
                throw new RException(error.ErrorText);
            }

            Debug.Assert(info is IRValueInfo);
            return((IRValueInfo)info);
        }
Beispiel #5
0
        public async Task EnvironmentIndependentResult()
        {
            const string code =
                @"(function(p) {
    v <- 42
    makeActiveBinding('a', function() 42, environment())
    browser()
  })(42)";

            var tracer = await _session.TraceExecutionAsync();

            using (var sf = new SourceFile(code)) {
                await tracer.EnableBreakpointsAsync(true);

                await sf.Source(_session);

                await _session.NextPromptShouldBeBrowseAsync();

                var stackFrames = (await _session.TracebackAsync()).ToArray();
                stackFrames.Should().NotBeEmpty();

                var env      = stackFrames.Last();
                var children = (await env.DescribeChildrenAsync(ExpressionProperty | ComputedValueProperty, RValueRepresentations.Deparse()));

                var v = children.Should().ContainSingle(er => er.Name == "v")
                        .Which.Should().BeAssignableTo <IRValueInfo>()
                        .Which;

                var p = children.Should().ContainSingle(er => er.Name == "p")
                        .Which.Should().BeAssignableTo <IRPromiseInfo>()
                        .Which;

                var a = children.Should().ContainSingle(er => er.Name == "a")
                        .Which.Should().BeAssignableTo <IRActiveBindingInfo>()
                        .Which;

                var e = (await env.TryEvaluateAndDescribeAsync("non_existing_variable", None, null))
                        .Should().BeAssignableTo <IRErrorInfo>()
                        .Which;

                var iv = v.ToEnvironmentIndependentResult().Should().BeAssignableTo <IRValueInfo>().Which;
                (await _session.EvaluateAndDescribeAsync(iv.Expression, ExpressionProperty, RValueRepresentations.Deparse()))
                .Should().BeAssignableTo <IRValueInfo>().Which.Representation.Should().Be(v.Representation);

                // When a promise expression is evaluated directly, rather than via children, the promise is forced
                // and becomes a value. To have something to compare it against, evaluate the original promise in
                // its original environment as well.
                var pv = await v.GetValueAsync(ExpressionProperty, RValueRepresentations.Deparse());

                var ipv = p.ToEnvironmentIndependentResult().Should().BeAssignableTo <IRPromiseInfo>().Which;
                (await _session.EvaluateAndDescribeAsync(ipv.Expression, ExpressionProperty, RValueRepresentations.Deparse()))
                .Should().BeAssignableTo <IRValueInfo>()
                .Which.Representation.Should().Be(pv.Representation);

                // When an active binding expression is evaluated directly, rather than via children, its active
                // binding nature is not discoverable, and it produces a value result.
                var iav = a.ToEnvironmentIndependentResult().Should().BeAssignableTo <IRActiveBindingInfo>().Which;
                (await _session.EvaluateAndDescribeAsync(iav.Expression, ExpressionProperty | ComputedValueProperty, RValueRepresentations.Deparse()))
                .Should().BeAssignableTo <IRValueInfo>().Which.Representation.Should().Be(a.ComputedValue.Representation);

                var ie = e.ToEnvironmentIndependentResult().Should().BeAssignableTo <IRErrorInfo>().Which;
                (await _session.TryEvaluateAndDescribeAsync(ie.Expression, ExpressionProperty, RValueRepresentations.Deparse()))
                .Should().BeAssignableTo <IRErrorInfo>();
            }
        }
        public static async Task <IObjectDetailsViewer> GetViewer(this IObjectDetailsViewerAggregator aggregator, IRSession session, string environmentExpression, string expression, CancellationToken cancellationToken = default(CancellationToken))
        {
            var preliminary = await session.TryEvaluateAndDescribeAsync(expression, TypeNameProperty | ClassesProperty | DimProperty | LengthProperty | FlagsProperty, null, cancellationToken) as IRValueInfo;

            return(preliminary != null?aggregator.GetViewer(preliminary) : null);
        }
 public static async Task<IObjectDetailsViewer> GetViewer(this IObjectDetailsViewerAggregator aggregator, IRSession session, string environmentExpression, string expression, CancellationToken cancellationToken = default(CancellationToken)) {
     var preliminary = await session.TryEvaluateAndDescribeAsync(expression, TypeNameProperty | ClassesProperty | DimProperty | LengthProperty, null, cancellationToken) as IRValueInfo;
     return preliminary != null ? aggregator.GetViewer(preliminary) : null;
 }