public async Task SourceRScriptTest(bool echo, string encoding)
        {
            await _workflow.RSessions.TrySwitchBrokerAsync(nameof(RInteractiveWorkflowCommandTest));

            await _workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo(
                                                                cranMirrorName : _settings.CranMirror,
                                                                codePage : _settings.RCodePage
                                                                ), null, 50000);

            var session = _workflow.RSession;
            await session.ExecuteAsync("sourced <- FALSE");

            var tracker = Substitute.For <IActiveWpfTextViewTracker>();

            tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns((IWpfTextView)null);

            var command = new SourceRScriptCommand(_workflow, tracker, echo);

            command.Should().BeSupported()
            .And.BeInvisibleAndDisabled();

            using (await _workflow.GetOrCreateVisualComponentAsync()) {
                const string code       = "sourced <- TRUE";
                var          textBuffer = new TextBufferMock(code, RContentTypeDefinition.ContentType);
                var          textView   = new WpfTextViewMock(textBuffer);

                tracker.GetLastActiveTextView(RContentTypeDefinition.ContentType).Returns(textView);
                tracker.LastActiveTextView.Returns(textView);

                command.Should().BeSupported()
                .And.BeVisibleAndDisabled();

                using (var sf = new SourceFile(code)) {
                    var document = new TextDocumentMock(textBuffer, sf.FilePath)
                    {
                        Encoding = Encoding.GetEncoding(encoding)
                    };

                    textBuffer.Properties[typeof(ITextDocument)] = document;

                    command.Should().BeSupported()
                    .And.BeVisibleAndEnabled();

                    var mutatedTask = EventTaskSources.IRSession.Mutated.Create(session);

                    await command.InvokeAsync().Should().BeCompletedAsync();

                    await mutatedTask.Should().BeCompletedAsync();

                    (await session.EvaluateAsync <bool>("sourced", REvaluationKind.Normal)).Should().BeTrue();
                }
            }
        }
Пример #2
0
        public async Task InitializeAsync()
        {
            await _remoteBroker.ConnectAsync(_workflow.RSessions);

            _replVisualComponent = await _workflow.GetOrCreateVisualComponentAsync();

            _plotManager = (IRPlotManagerVisual)_workflow.Plots;
            _plotDeviceVisualComponentContainerFactory.DeviceProperties = new PlotDeviceProperties(600, 500, 96);
        }
Пример #3
0
        public async Task InitializeAsync()
        {
            await _workflow.RSessions.TrySwitchBrokerAsync(nameof(RPlotIntegrationTest));

            _replVisualComponent = await _workflow.GetOrCreateVisualComponentAsync();

            _plotManager = (IRPlotManagerVisual)_workflow.Plots;
            _plotDeviceVisualComponentContainerFactory.DeviceProperties = new PlotDeviceProperties(600, 500, 96);
        }
Пример #4
0
        public async Task InitializeAsync()
        {
            await _workflow.RSessions.TrySwitchBrokerAsync(nameof(RPlotIntegrationUITest));

            _interactiveWindow = await _workflow.GetOrCreateVisualComponentAsync();

            _plotVisualComponent.Control.Width  = 600;
            _plotVisualComponent.Control.Height = 500;
            _containerDisposable = await _containerHost.AddToHost(_plotVisualComponent.Control);
        }
Пример #5
0
        public async Task ConnectAsync(IConnectionInfo connection, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (await TrySwitchBrokerAsync(connection, cancellationToken))
            {
                await _shell.SwitchToMainThreadAsync(cancellationToken);

                var interactiveWindow = await _interactiveWorkflow.GetOrCreateVisualComponentAsync();

                interactiveWindow.Container.Show(focus: false, immediate: false);
            }
        }
Пример #6
0
        public async Task InitializeProjectFromDiskAsync()
        {
            await Project.CreateInMemoryImport();

            _fileWatcher.Start();

            await _threadHandling.SwitchToUIThread();

            // Make sure R package is loaded
            VsAppShell.EnsurePackageLoaded(RGuidList.RPackageGuid);

            // Verify project is not on a network share and give warning if it is
            CheckRemoteDrive(_projectDirectory);

            _workflow = _coreShell.GetService <IRInteractiveWorkflowVisualProvider>().GetOrCreate();
            _session  = _workflow.RSession;
            _history  = _workflow.History;

            if (_workflow.ActiveWindow == null)
            {
                var window = await _workflow.GetOrCreateVisualComponentAsync();

                window.Container.Show(focus: true, immediate: false);
            }

            try {
                await _session.HostStarted;
            } catch (Exception) {
                return;
            }

            _workflow.RSessions.BeforeDisposed += BeforeRSessionsDisposed;

            // TODO: need to compute the proper paths for remote, but they might not even exist if the project hasn't been deployed.
            // https://github.com/Microsoft/RTVS/issues/2223
            if (!_session.IsRemote)
            {
                var  rdataPath            = Path.Combine(_projectDirectory, DefaultRDataName);
                bool loadDefaultWorkspace = _coreShell.FileSystem().FileExists(rdataPath) && await GetLoadDefaultWorkspace(rdataPath);

                if (loadDefaultWorkspace)
                {
                    await _session.LoadWorkspaceAsync(rdataPath);
                }
                await _session.SetWorkingDirectoryAsync(_projectDirectory);

                _settings.WorkingDirectory = _projectDirectory;
            }

            _history.TryLoadFromFile(Path.Combine(_projectDirectory, DefaultRHistoryName));
            CheckSurveyNews();
        }
Пример #7
0
        public async Task SendToReplTest()
        {
            string content = "x <- 1\r\ny <- 2\r\n";

            var editorBuffer = new TextBufferMock(content, RContentTypeDefinition.ContentType);
            var tv           = new TextViewMock(editorBuffer);

            var commandFactory = new VsRCommandFactory(_workflowProvider);
            var commands       = UIThreadHelper.Instance.Invoke(() => commandFactory.GetCommands(tv, editorBuffer));
            await _workflow.RSession.HostStarted.Should().BeCompletedAsync();

            await UIThreadHelper.Instance.Invoke(() => _workflow.GetOrCreateVisualComponentAsync());

            _workflow.ActiveWindow.Should().NotBeNull();

            var command = commands.OfType <SendToReplCommand>()
                          .Should().ContainSingle().Which;

            var replBuffer = _workflow.ActiveWindow.InteractiveWindow.CurrentLanguageBuffer;

            _workflow.ActiveWindow.Container.IsOnScreen.Should().BeFalse();

            Guid   group = VSConstants.VsStd11;
            int    id    = (int)VSConstants.VSStd11CmdID.ExecuteLineInInteractive;
            object o     = new object();

            command.Status(group, id).Should().Be(CommandStatus.SupportedAndEnabled);
            command.Invoke(group, id, null, ref o);

            replBuffer.CurrentSnapshot.GetText().Trim().Should().Be("x <- 1");

            int caretPos = tv.Caret.Position.BufferPosition.Position;
            int lineNum  = editorBuffer.CurrentSnapshot.GetLineNumberFromPosition(caretPos);

            lineNum.Should().Be(1);

            tv.Selection.Select(new SnapshotSpan(editorBuffer.CurrentSnapshot, new Span(0, 1)), false);
            command.Invoke(group, id, null, ref o);

            ITextSnapshotLine line = replBuffer.CurrentSnapshot.GetLineFromLineNumber(1);

            line.GetText().Trim().Should().Be("x");

            _workflow.ActiveWindow.Dispose();
        }
Пример #8
0
        private async Task WriteAsync(string text, bool isError)
        {
            await _mainThread.SwitchToAsync();

            if (_component == null)
            {
                _component = await _workflow.GetOrCreateVisualComponentAsync();

                _component.Container.Show(focus: false, immediate: false);
            }
            if (isError)
            {
                _component.InteractiveWindow.WriteError(text);
            }
            else
            {
                _component.InteractiveWindow.Write(text);
            }
        }
Пример #9
0
        public async Task EvaluatorTest01()
        {
            var session = _workflow.RSession;

            using (await UIThreadHelper.Instance.Invoke(() => _workflow.GetOrCreateVisualComponentAsync())) {
                _workflow.ActiveWindow.Should().NotBeNull();
                session.IsHostRunning.Should().BeTrue();

                var window = _workflow.ActiveWindow.InteractiveWindow;
                var eval   = window.Evaluator;

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

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

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

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

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

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

                result.Should().Be(ExecutionResult.Success);
                FlushOutput(window);
                text = window.OutputBuffer.CurrentSnapshot.GetText();
                text.TrimEnd().TrimEnd((char)0).Should().Be("[1] \"電話帳 全米のお\"");

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

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

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

                result.Should().Be(ExecutionResult.Success);
                FlushOutput(window);
                text = window.OutputBuffer.CurrentSnapshot.GetText();
                text.Should().Be(string.Empty);

                window.Operations.ClearView();
                await eval.ResetAsync(initialize : false);

                FlushOutput(window);
                text = window.OutputBuffer.CurrentSnapshot.GetText();
                text.Should()
                .Contain(Resources.rtvs_AutosavingWorkspace.Substring(0, 8))
                .And.Contain(Resources.MicrosoftRHostStopping)
                .And.Contain(Resources.MicrosoftRHostStopped);
            }
        }
 public async Task InitializeAsync()
 {
     _workflowComponent = await UIThreadHelper.Instance.Invoke(() => _workflow.GetOrCreateVisualComponentAsync());
 }