internal ReplWindowProxy(VisualStudioApp app, IInteractiveWindow window, ToolWindowPane toolWindow, ReplWindowProxySettings settings)
 {
     Assert.IsNotNull(app, "app is required");
     Assert.IsNotNull(window, "window is required");
     _app                   = app;
     _window                = window;
     _toolWindow            = toolWindow;
     _settings              = settings;
     _replWindowInfo        = _replWindows.GetOrCreateValue(toolWindow);
     _window.ReadyForInput += _replWindowInfo.OnReadyForInput;
     _editorOperations      = _app.ComponentModel.GetService <IEditorOperationsFactoryService>()
                              .GetEditorOperations(_window.TextView);
 }
        public static ReplWindowProxy Prepare(
            ReplWindowProxySettings settings,
            bool useIPython = false
            )
        {
            settings.AssertValid();

            var             app    = settings.CreateApp();
            ReplWindowProxy result = null;

            try {
                result = OpenInteractive(app, settings, useIPython ? "IPython" : "Standard");
                app    = null;

                for (int retries = 10; retries > 0; --retries)
                {
                    result.Reset();
                    result.ClearScreen();
                    result.ClearInput();

                    try {
                        var task = result.ExecuteText("print('READY')");
                        Assert.IsTrue(task.Wait(useIPython ? 30000 : 10000), "ReplWindow did not initialize in time");
                        if (!task.Result.IsSuccessful)
                        {
                            continue;
                        }
                    } catch (TaskCanceledException) {
                        continue;
                    }

                    result.WaitForTextEnd("READY", ">");
                    if (result.TextView.TextBuffer.CurrentSnapshot.Lines
                        .Any(l => l.GetText().Contains("Error using selected REPL back-end")) &&
                        useIPython)
                    {
                        Assert.Inconclusive("IPython is not available");
                    }
                    result.ClearScreen();
                    return(result);
                }
                Assert.Fail("ReplWindow did not initialize");
                return(null);
            } finally {
                if (app != null)
                {
                    app.Dispose();
                }
            }
        }
        private static ReplWindowProxy OpenInteractive(
            VisualStudioApp app,
            ReplWindowProxySettings settings,
            string executionMode
            )
        {
            var toolWindow = settings.ActivateInteractiveWindow(app, executionMode);

#if DEV14_OR_LATER
            var interactive = toolWindow != null ? ((IVsInteractiveWindow)toolWindow).InteractiveWindow : null;
#else
            var interactive = toolWindow as IInteractiveWindow;
#endif

            Assert.IsNotNull(interactive, "Could not find interactive window");
            return(new ReplWindowProxy(app, interactive, toolWindow, settings));
        }