public int LaunchProject(bool debug) { var config = debug ? _debugConfig : _runConfig; DebugLaunchHelper.RequireStartupFile(config); Uri url; int port; GetFullUrl(_serviceProvider, config, out url, out port); var env = new Dictionary <string, string> { { "SERVER_PORT", port.ToString() } }; if (url != null) { env["SERVER_HOST"] = url.Host; } config.Environment = PathUtils.MergeEnvironments(env, config.Environment); try { _serviceProvider.GetPythonToolsService().Logger?.LogEvent(Logging.PythonLogEvent.Launch, new Logging.LaunchInfo { IsDebug = debug, IsWeb = true, Version = config.Interpreter?.Version.ToString() ?? "" }); } catch (Exception ex) { Debug.Fail(ex.ToUnhandledExceptionMessage(GetType())); } if (debug) { if (url != null) { config.LaunchOptions[PythonConstants.WebBrowserUrlSetting] = url.AbsoluteUri; } using (var dsi = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) { dsi.Launch(); } } else { var psi = DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config); var process = Process.Start(psi); if (url != null && process != null) { StartBrowser(url.AbsoluteUri, () => process.HasExited) .ContinueWith(t => { process.Close(); }) .HandleAllExceptions(_serviceProvider, GetType()) .DoNotWait(); } } return(VSConstants.S_OK); }
private int Launch(LaunchConfiguration config, bool debug) { DebugLaunchHelper.RequireStartupFile(config); //if (factory.Id == _cpyInterpreterGuid || factory.Id == _cpy64InterpreterGuid) { // MessageBox.Show( // "The project is currently set to use the .NET debugger for IronPython debugging but the project is configured to start with a CPython interpreter.\r\n\r\nTo fix this change the debugger type in project properties->Debug->Launch mode.\r\nIf IronPython is not an available interpreter you may need to download it from http://ironpython.codeplex.com.", // "Visual Studio"); // return VSConstants.S_OK; //} try { if (debug) { if (string.IsNullOrEmpty(config.InterpreterArguments)) { config.InterpreterArguments = "-X:Debug"; } else if (config.InterpreterArguments.IndexOf("-X:Debug", StringComparison.OrdinalIgnoreCase) < 0) { config.InterpreterArguments = "-X:Debug " + config.InterpreterArguments; } var debugStdLib = _project.GetProperty(IronPythonLauncherOptions.DebugStandardLibrarySetting); bool debugStdLibResult; if (!bool.TryParse(debugStdLib, out debugStdLibResult) || !debugStdLibResult) { string interpDir = config.Interpreter.PrefixPath; config.InterpreterArguments += " -X:NoDebug \"" + System.Text.RegularExpressions.Regex.Escape(Path.Combine(interpDir, "Lib\\")) + ".*\""; } using (var dti = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) { // Set the CLR debugger dti.Info.clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine; dti.Info.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd; // Clear the CLSID list while launching, then restore it // so Dispose() can free it. var clsidList = dti.Info.pClsidList; dti.Info.pClsidList = IntPtr.Zero; dti.Info.dwClsidCount = 0; try { dti.Launch(); } finally { dti.Info.pClsidList = clsidList; } } } else { var psi = DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config); Process.Start(psi).Dispose(); } } catch (FileNotFoundException) { } return(VSConstants.S_OK); }
public int LaunchProject(bool debug) { var config = debug ? _debugConfig : _runConfig; Uri url; int port; GetFullUrl(config, out url, out port); var env = new Dictionary <string, string> { { "SERVER_PORT", port.ToString() } }; if (url != null) { env["SERVER_HOST"] = url.Host; } config.Environment = PathUtils.MergeEnvironments(env, config.Environment); if (debug) { _pyService.Logger.LogEvent(Logging.PythonLogEvent.Launch, 1); using (var dsi = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) { dsi.Launch(); } var debugger = (IVsDebugger)_serviceProvider.GetService(typeof(SVsShellDebugger)); if (url != null && debugger != null) { StartBrowser(url.AbsoluteUri, () => !IsDebugging(_serviceProvider, debugger)) .HandleAllExceptions(_serviceProvider, GetType()) .DoNotWait(); } } else { _pyService.Logger.LogEvent(Logging.PythonLogEvent.Launch, 0); var psi = DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config); var process = Process.Start(psi); if (url != null && process != null) { StartBrowser(url.AbsoluteUri, () => process.HasExited) .ContinueWith(t => { process.Close(); }) .HandleAllExceptions(_serviceProvider, GetType()) .DoNotWait(); } } return(VSConstants.S_OK); }
/// <summary> /// Default implementation of the "Start without Debugging" command. /// </summary> private Process StartWithoutDebugger(LaunchConfiguration config) { try { _serviceProvider.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.Launch, new Logging.LaunchInfo { IsDebug = false, Version = config.Interpreter?.Version.ToString() ?? "" }); } catch (Exception ex) { Debug.Fail(ex.ToUnhandledExceptionMessage(GetType())); } return(Process.Start(DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config))); }
/// <summary> /// Default implementation of the "Start Debugging" command. /// </summary> private void StartWithDebugger(LaunchConfiguration config) { _serviceProvider.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.Launch, 1); // Historically, we would clear out config.InterpreterArguments at // this stage if doing mixed-mode debugging. However, there doesn't // seem to be any need to do this, so we now leave them alone. using (var dbgInfo = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) { dbgInfo.Launch(); } }
private int Launch(LaunchConfiguration config, bool debug) { DebugLaunchHelper.RequireStartupFile(config); if (debug) { StartWithDebugger(config); } else { StartWithoutDebugger(config).Dispose(); } return(VSConstants.S_OK); }
/// <summary> /// Default implementation of the "Start Debugging" command. /// </summary> private void StartWithDebugger(LaunchConfiguration config) { try { _serviceProvider.GetPythonToolsService().Logger?.LogEvent(Logging.PythonLogEvent.Launch, new Logging.LaunchInfo { IsDebug = true, Version = config.Interpreter?.Version.ToString() ?? "" }); } catch (Exception ex) { Debug.Fail(ex.ToUnhandledExceptionMessage(GetType())); } // Historically, we would clear out config.InterpreterArguments at // this stage if doing mixed-mode debugging. However, there doesn't // seem to be any need to do this, so we now leave them alone. using (var dbgInfo = DebugLaunchHelper.CreateDebugTargetInfo(_serviceProvider, config)) { dbgInfo.Launch(); } }
private void StartInterpreter_Executed(object sender, ExecutedRoutedEventArgs e) { var view = (EnvironmentView)e.Parameter; var config = new LaunchConfiguration(view.Factory.Configuration) { PreferWindowedInterpreter = (e.Command == EnvironmentPathsExtension.StartWindowsInterpreter), WorkingDirectory = view.Factory.Configuration.PrefixPath, SearchPaths = new List <string>() }; var sln = (IVsSolution)_site.GetService(typeof(SVsSolution)); foreach (var pyProj in sln.EnumerateLoadedPythonProjects()) { if (pyProj.InterpreterConfigurations.Contains(config.Interpreter)) { config.SearchPaths.AddRange(pyProj.GetSearchPaths()); } } Process.Start(DebugLaunchHelper.CreateProcessStartInfo(_site, config)).Dispose(); }
/// <summary> /// Default implementation of the "Start without Debugging" command. /// </summary> private Process StartWithoutDebugger(LaunchConfiguration config) { _serviceProvider.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.Launch, 0); return(Process.Start(DebugLaunchHelper.CreateProcessStartInfo(_serviceProvider, config))); }