private void OpenInteractiveWindow_Executed(object sender, ExecutedRoutedEventArgs e) { var view = (EnvironmentView)e.Parameter; var config = view.Factory.Configuration; var replId = PythonReplEvaluatorProvider.GetEvaluatorId(config); var compModel = _site.GetComponentModel(); var service = compModel.GetService <InteractiveWindowProvider>(); IVsInteractiveWindow window; // TODO: Figure out another way to get the project //var provider = _service.KnownProviders.OfType<LoadedProjectInterpreterFactoryProvider>().FirstOrDefault(); //var vsProject = provider == null ? // null : // provider.GetProject(factory); //PythonProjectNode project = vsProject == null ? null : vsProject.GetPythonProject(); try { window = service.OpenOrCreate(replId); } catch (Exception ex) when(!ex.IsCriticalException()) { TaskDialog.ForException(_site, ex, Strings.ErrorOpeningInteractiveWindow, PythonConstants.IssueTrackerUrl).ShowModal(); return; } window?.Show(true); }
internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService <InteractiveWindowProvider>(); var vsProjectContext = compModel.GetService <VsProjectContextProvider>(); var projectId = project != null?PythonReplEvaluatorProvider.GetEvaluatorId(project) : null; var configId = config != null?PythonReplEvaluatorProvider.GetEvaluatorId(config) : null; if (config?.IsRunnable() == false) { throw new MissingInterpreterException( Strings.MissingEnvironment.FormatUI(config.Description, config.Version) ); } IVsInteractiveWindow window; // If we find an open window for the project, prefer that to a per-config one if (!string.IsNullOrEmpty(projectId)) { window = provider.Open( projectId, e => ((e as SelectableReplEvaluator)?.Evaluator as PythonCommonInteractiveEvaluator)?.AssociatedProjectHasChanged != true ); if (window != null) { return(window); } } // If we find an open window for the configuration, return that if (!string.IsNullOrEmpty(configId)) { window = provider.Open(configId); if (window != null) { return(window); } } // No window found, so let's create one if (!string.IsNullOrEmpty(projectId)) { window = provider.Create(projectId); project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId)); } else if (!string.IsNullOrEmpty(configId)) { window = provider.Create(configId); } else { var interpService = compModel.GetService <IInterpreterOptionsService>(); window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration)); } return(window); }
void IVsPython.OpenInteractive(string description) { var compModel = _pyService.ComponentModel; if (compModel == null) { throw new InvalidOperationException("Could not activate component model"); } var provider = compModel.GetService <InteractiveWindowProvider>(); var interpreters = compModel.GetService <IInterpreterRegistryService>(); var factory = interpreters.Configurations.FirstOrDefault( f => f.Description.Equals(description, StringComparison.CurrentCultureIgnoreCase) ); if (factory == null) { throw new KeyNotFoundException("Could not create interactive window with name: " + description); } var window = provider.OpenOrCreate( PythonReplEvaluatorProvider.GetEvaluatorId(factory) ); if (window == null) { throw new InvalidOperationException("Could not create interactive window"); } window.Show(true); }
internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService <InteractiveWindowProvider>(); var vsProjectContext = compModel.GetService <VsProjectContextProvider>(); var projectId = project != null?PythonReplEvaluatorProvider.GetEvaluatorId(project) : null; var configId = config != null?PythonReplEvaluatorProvider.GetEvaluatorId(config) : null; IVsInteractiveWindow window; // If we find an open window for the project, prefer that to a per-config one if (!string.IsNullOrEmpty(projectId)) { window = provider.Open(projectId); if (window != null) { if (window.InteractiveWindow.GetPythonEvaluator()?.AssociatedProjectHasChanged == true) { // We have an existing window, but it needs to be reset. // Let's create a new one window = provider.Create(projectId); project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId)); } return(window); } } // If we find an open window for the configuration, return that if (!string.IsNullOrEmpty(configId)) { window = provider.Open(configId); if (window != null) { return(window); } } // No window found, so let's create one if (!string.IsNullOrEmpty(projectId)) { window = provider.Create(projectId); project.AddActionOnClose(window, w => InteractiveWindowProvider.CloseIfEvaluatorMatches(w, projectId)); } else if (!string.IsNullOrEmpty(configId)) { window = provider.Create(configId); } else { var interpService = compModel.GetService <IInterpreterOptionsService>(); window = provider.Create(PythonReplEvaluatorProvider.GetEvaluatorId(interpService.DefaultInterpreter.Configuration)); } return(window); }
public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode) { string description = null; if (Version.IsCPython) { description = string.Format("{0} {1}", Version.Isx64 ? "Python 64-bit" : "Python 32-bit", Version.Version.ToVersion() ); } else if (Version.IsIronPython) { description = string.Format("{0} {1}", Version.Isx64 ? "IronPython 64-bit" : "IronPython", Version.Version.ToVersion() ); } Assert.IsNotNull(description, "Unknown interpreter"); var automation = (IVsPython)app.Dte.GetObject("VsPython"); var options = (IPythonOptions)automation; var replOptions = options.Interactive; Assert.IsNotNull(replOptions, "Could not find options for " + description); var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord; app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord); options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord; bool success = false; for (int retries = 1; retries < 20; ++retries) { try { app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\""); success = true; break; } catch (AggregateException) { } app.DismissAllDialogs(); app.SetFocus(); Thread.Sleep(retries * 100); } Assert.IsTrue(success, "Unable to open " + description + " through DTE"); var interpreters = app.ComponentModel.GetService <IInterpreterRegistryService>(); var replId = PythonReplEvaluatorProvider.GetEvaluatorId( interpreters.FindConfiguration(Version.Id) ); return(app.ServiceProvider.GetUIThread().Invoke(() => { var provider = app.ComponentModel.GetService <InteractiveWindowProvider>(); return (ToolWindowPane)provider.OpenOrCreate(replId); })); }
private static ToolWindowPane ActivateInteractiveWindow(ReplWindowProxySettings settings, VisualStudioApp app, string projectName, string workspaceName, string backend) { string description = null; if (settings.Version.IsCPython) { description = string.Format("{0} {1}", settings.Version.Isx64 ? "Python 64-bit" : "Python 32-bit", settings.Version.Version.ToVersion() ); } else if (settings.Version.IsIronPython) { description = string.Format("{0} {1}", settings.Version.Isx64 ? "IronPython 64-bit" : "IronPython", settings.Version.Version.ToVersion() ); } Assert.IsNotNull(description, "Unknown interpreter"); var automation = (IVsPython)app.Dte.GetObject("VsPython"); var options = (IPythonOptions)automation; var replOptions = options.Interactive; Assert.IsNotNull(replOptions, "Could not find options for " + description); var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord; app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord); options.Intellisense.AddNewLineAtEndOfFullyTypedWord = settings.AddNewLineAtEndOfFullyTypedWord; var interpreters = app.ComponentModel.GetService <IInterpreterRegistryService>(); var replId = PythonReplEvaluatorProvider.GetEvaluatorId( interpreters.FindConfiguration(settings.Version.Id) ); if (!string.IsNullOrEmpty(projectName)) { var dteProj = app.GetProject(projectName); var proj = (PythonProjectNode)dteProj.GetCommonProject(); replId = PythonReplEvaluatorProvider.GetEvaluatorId(proj); } else if (!string.IsNullOrEmpty(workspaceName)) { var workspaceContextProvider = app.ComponentModel.GetService <IPythonWorkspaceContextProvider>(); replId = PythonReplEvaluatorProvider.GetEvaluatorId(workspaceContextProvider.Workspace); } return(app.ServiceProvider.GetUIThread().Invoke(() => { app.ServiceProvider.GetPythonToolsService().InteractiveBackendOverride = backend; var provider = app.ComponentModel.GetService <InteractiveWindowProvider>(); return (ToolWindowPane)provider.OpenOrCreate(replId); })); }
internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project) { var compModel = serviceProvider.GetComponentModel(); var provider = compModel.GetService <InteractiveWindowProvider>(); var vsProjectContext = compModel.GetService <VsProjectContextProvider>(); string replId = config != null? PythonReplEvaluatorProvider.GetEvaluatorId(config) : PythonReplEvaluatorProvider.GetEvaluatorId(project); var window = provider.OpenOrCreate(replId); project?.AddActionOnClose(window, InteractiveWindowProvider.Close); return(window); }
public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode) { string description = null; if (Version.IsCPython) { description = string.Format("{0} {1}", Version.Isx64 ? "Python 64-bit" : "Python 32-bit", Version.Version.ToVersion() ); } else if (Version.IsIronPython) { description = string.Format("{0} {1}", Version.Isx64 ? "IronPython 64-bit" : "IronPython", Version.Version.ToVersion() ); } Assert.IsNotNull(description, "Unknown interpreter"); var automation = (IVsPython)app.Dte.GetObject("VsPython"); var options = (IPythonOptions)automation; var replOptions = options.Interactive; Assert.IsNotNull(replOptions, "Could not find options for " + description); var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord; app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord); options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord; var interpreters = app.ComponentModel.GetService <IInterpreterRegistryService>(); var replId = PythonReplEvaluatorProvider.GetEvaluatorId( interpreters.FindConfiguration(Version.Id) ); return(app.ServiceProvider.GetUIThread().Invoke(() => { var provider = app.ComponentModel.GetService <InteractiveWindowProvider>(); return (ToolWindowPane)provider.OpenOrCreate(replId); })); }