public void LaunchWebBrowserUriTests() { var testCases = new[] { new { Url = "/fob", Port = 1, Expected = "http://localhost:1/fob" }, new { Url = "http://localhost:9999/fob", Port = 9999, Expected = "http://localhost:9999/fob" }, new { Url = "http://localhost/fob", Port = 9999, Expected = "http://localhost:9999/fob" }, new { Url = "fob", Port = 9999, Expected = "http://localhost:9999/fob" }, new { Url = "/hello/world", Port = 367, Expected = "http://localhost:367/hello/world" }, new { Url = "/fob", Port = -1, Expected = "http://localhost:{port}/fob" }, }; foreach (var testCase in testCases) { Console.WriteLine("{0} {1} == {2}", testCase.Url, testCase.Port, testCase.Expected); Uri url; int port; var config = new LaunchConfiguration(null, new Dictionary <string, string> { { PythonConstants.WebBrowserUrlSetting, testCase.Url } }); if (testCase.Port >= 0) { config.LaunchOptions[PythonConstants.WebBrowserPortSetting] = testCase.Port.ToString(); } PythonWebLauncher.GetFullUrl(null, config, out url, out port); Assert.AreEqual( testCase.Expected.Replace("{port}", port.ToString()), url.AbsoluteUri ); } }
public void LaunchWebBrowserUriTests() { var testCases = new[] { new { Url = "/fob", Port = 0, Expected = "http://localhost:0/fob" }, new { Url = "http://localhost:9999/fob", Port = 9999, Expected = "http://localhost:9999/fob" }, new { Url = "http://localhost/fob", Port = 9999, Expected = "http://localhost:9999/fob" }, new { Url = "fob", Port = 9999, Expected = "http://localhost:9999/fob" }, new { Url = "/hello/world", Port = 367, Expected = "http://localhost:367/hello/world" }, }; foreach (var testCase in testCases) { Console.WriteLine("{0} {1} == {2}", testCase.Url, testCase.Port, testCase.Expected); Assert.AreEqual( PythonWebLauncher.GetFullUrl(testCase.Url, testCase.Port), testCase.Expected ); } }
public void LaunchDebugTarget(IWorkspace workspace, IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext) { var registry = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>(); var settings = debugLaunchActionContext.LaunchConfiguration; var scriptName = settings.GetValue(ScriptNameKey, string.Empty); var debug = !settings.GetValue("noDebug", false); var path = settings.GetValue(InterpreterKey, string.Empty); InterpreterConfiguration config = null; if (string.IsNullOrEmpty(scriptName)) { throw new InvalidOperationException(Strings.DebugLaunchScriptNameMissing); } if (!string.IsNullOrEmpty(path) && !DefaultInterpreterValue.Equals(path, StringComparison.OrdinalIgnoreCase)) { if (PathUtils.IsValidPath(path) && !Path.IsPathRooted(path)) { // Cannot (currently?) get the workspace path easily from here, so we'll start from // the startup file and work our way up until we find it. var basePath = PathUtils.GetParent(scriptName); string candidate = null; while (Directory.Exists(basePath)) { candidate = PathUtils.GetAbsoluteFilePath(basePath, path); if (File.Exists(candidate)) { path = candidate; break; } basePath = PathUtils.GetParent(basePath); } } if (File.Exists(path)) { config = registry.Configurations.FirstOrDefault(c => c.InterpreterPath.Equals(path, StringComparison.OrdinalIgnoreCase)) ?? new InterpreterConfiguration("Custom", path, PathUtils.GetParent(path), path); } else { config = registry.FindConfiguration(path); } } else { var service = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); service.DefaultInterpreter.ThrowIfNotRunnable(); config = service.DefaultInterpreter.Configuration; path = config.InterpreterPath; } if (!File.Exists(path)) { throw new InvalidOperationException(Strings.DebugLaunchInterpreterMissing_Path.FormatUI(path)); } IProjectLauncher launcher = null; var launchConfig = new LaunchConfiguration(config) { InterpreterPath = config == null ? path : null, InterpreterArguments = settings.GetValue(InterpreterArgumentsKey, string.Empty), ScriptName = scriptName, ScriptArguments = settings.GetValue(ScriptArgumentsKey, string.Empty), WorkingDirectory = settings.GetValue(WorkingDirectoryKey, string.Empty), // TODO: Support search paths SearchPaths = null, // TODO: Support env variables Environment = null, }; launchConfig.LaunchOptions[PythonConstants.EnableNativeCodeDebugging] = settings.GetValue(NativeDebuggingKey, false).ToString(); var browserUrl = settings.GetValue(WebBrowserUrlKey, string.Empty); if (!string.IsNullOrEmpty(browserUrl)) { launchConfig.LaunchOptions[PythonConstants.WebBrowserUrlSetting] = browserUrl; launcher = new PythonWebLauncher(serviceProvider, launchConfig, launchConfig, launchConfig); } (launcher ?? new DefaultPythonLauncher(serviceProvider, launchConfig)).LaunchProject(debug); }
public void LaunchDebugTarget(IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext) { var registry = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>(); var settings = debugLaunchActionContext.LaunchConfiguration; var debug = !settings.GetValue("noDebug", false); var path = settings.GetValue(InterpreterKey, string.Empty); InterpreterConfiguration config = null; if (!string.IsNullOrEmpty(path)) { if (PathUtils.IsValidPath(path) && !Path.IsPathRooted(path)) { // TODO: Find location of launch.json } if (File.Exists(path)) { config = registry.Configurations.FirstOrDefault(c => c.InterpreterPath.Equals(path, StringComparison.OrdinalIgnoreCase)) ?? new InterpreterConfiguration("Custom", path, PathUtils.GetParent(path), path); } else { config = registry.FindConfiguration(path); } } else { var service = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); service.DefaultInterpreter.ThrowIfNotRunnable(); config = service.DefaultInterpreter.Configuration; path = config.InterpreterPath; } if (!File.Exists(path)) { throw new InvalidOperationException(Strings.DebugLaunchInterpreterMissing_Path.FormatUI(path)); } IProjectLauncher launcher = null; var launchConfig = new LaunchConfiguration(config) { InterpreterPath = config == null ? path : null, InterpreterArguments = settings.GetValue(InterpreterArgumentsKey, string.Empty), ScriptName = settings.GetValue(ScriptNameKey, string.Empty), ScriptArguments = settings.GetValue(ScriptArgumentsKey, string.Empty), WorkingDirectory = settings.GetValue(WorkingDirectoryKey, string.Empty), // TODO: Support search paths SearchPaths = null, // TODO: Support env variables Environment = null, }; launchConfig.LaunchOptions[PythonConstants.EnableNativeCodeDebugging] = settings.GetValue(NativeDebuggingKey, false).ToString(); var browserUrl = settings.GetValue(WebBrowserUrlKey, string.Empty); if (!string.IsNullOrEmpty(browserUrl)) { launchConfig.LaunchOptions[PythonConstants.WebBrowserUrlSetting] = browserUrl; launcher = new PythonWebLauncher(serviceProvider, launchConfig, launchConfig, launchConfig); } (launcher ?? new DefaultPythonLauncher(serviceProvider, launchConfig)).LaunchProject(debug); }
public void LaunchDebugTarget(IWorkspace workspace, IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext) { var registry = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>(); var settings = debugLaunchActionContext.LaunchConfiguration; var scriptName = settings.GetValue(ScriptNameKey, string.Empty); var debug = !settings.GetValue("noDebug", false); var interpreterVal = settings.GetValue(InterpreterKey, string.Empty); var path = interpreterVal; InterpreterConfiguration config = null; if (string.IsNullOrEmpty(scriptName)) { throw new InvalidOperationException(Strings.DebugLaunchScriptNameMissing); } if (!string.IsNullOrEmpty(path) && !DefaultInterpreterValue.Equals(path, StringComparison.OrdinalIgnoreCase)) { if (PathUtils.IsValidPath(path) && !Path.IsPathRooted(path)) { path = workspace.MakeRooted(path); } if (File.Exists(path)) { config = registry.Configurations.FirstOrDefault(c => c.InterpreterPath.Equals(path, StringComparison.OrdinalIgnoreCase)) ?? new VisualStudioInterpreterConfiguration("Custom", path, PathUtils.GetParent(path), path); } else { config = registry.FindConfiguration(interpreterVal); } } else { var options = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>(); var interpreter = workspace.GetInterpreterFactory(registry, options); interpreter.ThrowIfNotRunnable(); config = interpreter.Configuration; path = config.InterpreterPath; } if (!File.Exists(path)) { throw new InvalidOperationException(Strings.DebugLaunchInterpreterMissing_Path.FormatUI(path)); } var searchPaths = workspace.GetAbsoluteSearchPaths().ToList(); var environment = new Dictionary <string, string>(); if (settings.TryGetValue <IPropertySettings>(EnvKey, out IPropertySettings envSettings)) { foreach (var keyVal in envSettings) { environment[keyVal.Key] = keyVal.Value.ToString(); } } string workingDir = settings.GetValue(WorkingDirectoryKey, string.Empty); if (string.IsNullOrEmpty(workingDir)) { workingDir = workspace.MakeRooted("."); } else if (PathUtils.IsValidPath(workingDir) && !Path.IsPathRooted(workingDir)) { workingDir = workspace.MakeRooted(workingDir); } var launchConfig = new LaunchConfiguration(config) { InterpreterPath = config == null ? path : null, InterpreterArguments = settings.GetValue(InterpreterArgumentsKey, string.Empty), ScriptName = Path.IsPathRooted(scriptName) ? scriptName : Path.Combine(workingDir, scriptName), ScriptArguments = settings.GetValue(ScriptArgumentsKey, string.Empty), WorkingDirectory = workingDir, SearchPaths = searchPaths, Environment = environment, }; launchConfig.LaunchOptions[PythonConstants.EnableNativeCodeDebugging] = settings.GetValue(NativeDebuggingKey, false).ToString(); IProjectLauncher launcher = null; var browserUrl = settings.GetValue(WebBrowserUrlKey, string.Empty); if (!string.IsNullOrEmpty(browserUrl)) { launchConfig.LaunchOptions[PythonConstants.WebBrowserUrlSetting] = browserUrl; launcher = new PythonWebLauncher(serviceProvider, launchConfig, launchConfig, launchConfig); } (launcher ?? new DefaultPythonLauncher(serviceProvider, launchConfig)).LaunchProject(debug); }