Exemplo n.º 1
0
        public async Task ViewAsync(string expression, string title) {
            var evaluation = await EvaluateAsync(expression, REvaluationResultProperties.ExpressionProperty, null);
            if (evaluation == null || string.IsNullOrEmpty(evaluation.Expression)) {
                return;
            }

            var functionName = evaluation.Expression;
            var session = _sessionProvider.GetInteractiveWindowRSession();

            string functionCode = await GetFunctionCode(functionName);
            if (!string.IsNullOrEmpty(functionCode)) {

                string tempFile = GetFileName(functionName, title);
                try {
                    if (File.Exists(tempFile)) {
                        File.Delete(tempFile);
                    }

                    using (var sw = new StreamWriter(tempFile)) {
                        sw.Write(functionCode);
                    }

                    await VsAppShell.Current.SwitchToMainThreadAsync();

                    FileViewer.ViewFile(tempFile, functionName);
                    try {
                        File.Delete(tempFile);
                    } catch (IOException) { } catch (AccessViolationException) { }

                } catch (IOException) { } catch (AccessViolationException) { }
            }
        }
Exemplo n.º 2
0
        public VariableProvider(
            [Import(typeof(IRSessionProvider))] IRSessionProvider sessionProvider,
            [Import(typeof(IDebugSessionProvider))] IDebugSessionProvider debugSessionProvider)
        {
            if (sessionProvider == null)
            {
                throw new ArgumentNullException(nameof(sessionProvider));
            }
            if (debugSessionProvider == null)
            {
                throw new ArgumentNullException(nameof(debugSessionProvider));
            }


            RSession = sessionProvider.GetInteractiveWindowRSession();
            if (RSession == null)
            {
                throw new InvalidOperationException(Invariant($"{nameof(IRSessionProvider)} failed to return RSession for {nameof(IVariableDataProvider)}"));
            }
            RSession.Mutated += RSession_Mutated;

            IdleTimeAction.Create(() => {
                PublishAllAsync().SilenceException <Exception>().DoNotWait();
            }, 10, typeof(VariableProvider));
        }
Exemplo n.º 3
0
        public async Task <IREvaluationResultInfo> EvaluateAsync(string expression, REvaluationResultProperties fields, string repr = null)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            repr = repr ?? RValueRepresentations.Str();

            // Don't cache sessions since they can be disposed, expecially the debug session
            // when host is restarts or gets re-created in tests
            var rSession = _rSessionProvider.GetInteractiveWindowRSession();

            var frames = await rSession.TracebackAsync();

            if (frames == null || frames.Count == 0)
            {
                throw new InvalidOperationException("Debugger frames stack is empty");
            }
            return(await frames.Last().TryEvaluateAndDescribeAsync(expression, fields, repr) as IRValueInfo);
        }
Exemplo n.º 4
0
 public OpenRDataCommandGroupHandler(UnconfiguredProject unconfiguredProject, IRSessionProvider sessionProvider, params long[] commandIds)
 {
     _unconfiguredProject = unconfiguredProject;
     _session             = sessionProvider.GetInteractiveWindowRSession();
     _commandIds          = commandIds;
 }
 public OpenRDataCommandGroupHandler(UnconfiguredProject unconfiguredProject, IRSessionProvider sessionProvider, params long[] commandIds) {
     _unconfiguredProject = unconfiguredProject;
     _session = sessionProvider.GetInteractiveWindowRSession();
     _commandIds = commandIds;
 }
Exemplo n.º 6
0
        public async Task EvaluatorTest01()
        {
            using (new VsRHostScript()) {
                var session = _sessionProvider.GetInteractiveWindowRSession();
                using (var eval = new RInteractiveEvaluator(session, RHistoryStubFactory.CreateDefault(), VsAppShell.Current, RToolsSettings.Current)) {
                    var tb = new TextBufferMock(string.Empty, RContentTypeDefinition.ContentType);
                    var tv = new WpfTextViewMock(tb);

                    var iwm = new InteractiveWindowMock(tv);
                    eval.CurrentWindow = iwm;

                    var result = await eval.InitializeAsync();

                    result.Should().Be(ExecutionResult.Success);
                    session.IsHostRunning.Should().BeTrue();

                    eval.CanExecuteCode("x <-").Should().BeFalse();
                    eval.CanExecuteCode("(()").Should().BeFalse();
                    eval.CanExecuteCode("a *(b+c)").Should().BeTrue();

                    VsRHostScript.DoIdle(300);

                    result = await eval.ExecuteCodeAsync(new string(new char[10000]) + "\r\n");

                    result.Should().Be(ExecutionResult.Failure);
                    string text = tb.CurrentSnapshot.GetText();
                    text.Should().Contain(string.Format(Microsoft.R.Components.Resources.InputIsTooLong, 4096));
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("z <- '電話帳 全米のお'\n");

                    result.Should().Be(ExecutionResult.Success);
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("z" + Environment.NewLine);

                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.TrimEnd().Should().Be("[1] \"電話帳 全米のお\"");
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("Encoding(z)\n");

                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.TrimEnd().Should().Be("[1] \"UTF-8\"");
                    tb.Clear();

                    result = await eval.ExecuteCodeAsync("x <- c(1:10)\n");

                    result.Should().Be(ExecutionResult.Success);
                    text = tb.CurrentSnapshot.GetText();
                    text.Should().Be(string.Empty);
                    tb.Clear();

                    await eval.ResetAsync(initialize : false);

                    text = tb.CurrentSnapshot.GetText();
                    text.Should().StartWith(Microsoft.R.Components.Resources.MicrosoftRHostStopping);
                }
            }
        }