Exemple #1
0
        protected string CheckNodeInstalledAndWarn(DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = debugLaunchContext.LaunchConfiguration.GetValue(NodeExeKey, defaultValue: Nodejs.GetPathToNodeExecutableFromEnvironment());

            // Similar to the project case, as long as we have a value we're good
            if (!string.IsNullOrEmpty(nodeExe))
            {
                return(nodeExe);
            }

            var workspace = this.WorkspaceService.CurrentWorkspace;

            workspace.JTF.Run(async() =>
            {
                await workspace.JTF.SwitchToMainThreadAsync();

                VsShellUtilities.ShowMessageBox(this.ServiceProvider,
                                                string.Format(Resources.NodejsNotInstalledAnyCode, LaunchConfigurationConstants.LaunchJsonFileName),
                                                Resources.NodejsNotInstalledShort,
                                                OLEMSGICON.OLEMSGICON_CRITICAL,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            });

            // This isn't pretty but the only way to not get an additional
            // dialog box, after the one we show.
            throw new TaskCanceledException();
        }
 public void CustomizeLaunchConfiguration(DebugLaunchActionContext debugLaunchActionContext, IPropertySettings launchSettings) {
     launchSettings[PythonLaunchDebugTargetProvider.InterpreterKey] = "(default)";
     launchSettings[PythonLaunchDebugTargetProvider.InterpreterArgumentsKey] = string.Empty;
     launchSettings[PythonLaunchDebugTargetProvider.ScriptArgumentsKey] = string.Empty;
     launchSettings[PythonLaunchDebugTargetProvider.NativeDebuggingKey] = false;
     launchSettings[PythonLaunchDebugTargetProvider.WebBrowserUrlKey] = string.Empty;
 }
Exemple #3
0
        public void LaunchDebugTarget(IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext)
        {
            var settings = debugLaunchActionContext.LaunchConfiguration;
            var moniker  = settings.GetValue(ProjectKey, string.Empty);

            if (string.IsNullOrEmpty(moniker))
            {
                throw new InvalidOperationException();
            }

            var solution  = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
            var solution4 = solution as IVsSolution4;
            var debugger  = serviceProvider.GetShellDebugger();

            if (solution == null || solution4 == null)
            {
                throw new InvalidOperationException();
            }

            solution4.EnsureSolutionIsLoaded(0);
            var proj = solution.EnumerateLoadedPythonProjects()
                       .FirstOrDefault(p => string.Equals(p.GetMkDocument(), moniker, StringComparison.OrdinalIgnoreCase));

            if (proj == null)
            {
                throw new InvalidOperationException();
            }

            ErrorHandler.ThrowOnFailure(proj.GetLauncher().LaunchProject(true));
        }
        public void LaunchDebugTarget(IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext) {
            var settings = debugLaunchActionContext.LaunchConfiguration;
            var moniker = settings.GetValue(ProjectKey, string.Empty);
            if (string.IsNullOrEmpty(moniker)) {
                throw new InvalidOperationException();
            }

            var solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
            var solution4 = solution as IVsSolution4;
            var debugger = serviceProvider.GetShellDebugger();

            if (solution == null || solution4 == null) {
                throw new InvalidOperationException();
            }

            solution4.EnsureSolutionIsLoaded(0);
            var proj = solution.EnumerateLoadedPythonProjects()
                .FirstOrDefault(p => string.Equals(p.GetMkDocument(), moniker, StringComparison.OrdinalIgnoreCase));

            if (proj == null) {
                throw new InvalidOperationException();
            }

            ErrorHandler.ThrowOnFailure(proj.GetLauncher().LaunchProject(true));
        }
Exemple #5
0
 public void CustomizeLaunchConfiguration(DebugLaunchActionContext debugLaunchActionContext, IPropertySettings launchSettings)
 {
     launchSettings[PythonLaunchDebugTargetProvider.InterpreterKey]          = "(default)";
     launchSettings[PythonLaunchDebugTargetProvider.InterpreterArgumentsKey] = string.Empty;
     launchSettings[PythonLaunchDebugTargetProvider.ScriptArgumentsKey]      = string.Empty;
     launchSettings[PythonLaunchDebugTargetProvider.NativeDebuggingKey]      = false;
     launchSettings[PythonLaunchDebugTargetProvider.WebBrowserUrlKey]        = string.Empty;
 }
        public bool IsDebugLaunchActionSupported(DebugLaunchActionContext debugLaunchActionContext) {
            var settings = debugLaunchActionContext.LaunchConfiguration;
            var moniker = settings.GetValue(PyprojLaunchDebugTargetProvider.ProjectKey, string.Empty);
            if (string.IsNullOrEmpty(moniker) || !string.Equals(Path.GetExtension(moniker), ".pyproj", StringComparison.OrdinalIgnoreCase)) {
                return false;
            }

            return true;
        }
        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);
        }
Exemple #8
0
        public bool IsDebugLaunchActionSupported(DebugLaunchActionContext debugLaunchActionContext)
        {
            var settings = debugLaunchActionContext.LaunchConfiguration;
            var moniker  = settings.GetValue(PyprojLaunchDebugTargetProvider.ProjectKey, string.Empty);

            if (string.IsNullOrEmpty(moniker) || !FileExtension.Equals(Path.GetExtension(moniker), StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext) {
            string target = vsDebugTargetInfo.bstrExe;
            vsDebugTargetInfo.bstrExe = debugLaunchContext.LaunchConfiguration.GetValue<string>(NodeExeKey, Nodejs.GetPathToNodeExecutableFromEnvironment());
            string nodeJsArgs = vsDebugTargetInfo.bstrArg;
            vsDebugTargetInfo.bstrArg = "\"" + target + "\"";
            if (!string.IsNullOrEmpty(nodeJsArgs))
            {
                vsDebugTargetInfo.bstrArg += " ";
                vsDebugTargetInfo.bstrArg += nodeJsArgs;
            }

            vsDebugTargetInfo.clsidCustom = DebugEngine.AD7Engine.DebugEngineGuid;
            vsDebugTargetInfo.bstrOptions = "WAIT_ON_ABNORMAL_EXIT=true";
            vsDebugTargetInfo.grfLaunch = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Exemple #10
0
        private static readonly Guid ManagedOnlyGuid = new Guid("{449EC4CC-30D2-4032-9256-EE18EB41B62B}"); // taken from VSConstants.DebugEnginesGuids.ManagedOnly_guid

        public object SetupDebugTargetInfo(object vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            if (!debugLaunchContext.LaunchConfiguration.ContainsKey("scriptcs_exe"))
            {
                return(vsDebugTargetInfo);
            }

            var scriptcs  = debugLaunchContext.LaunchConfiguration.GetValue <string>("scriptcs_exe");
            var debugInfo = (VsDebugTargetInfo)vsDebugTargetInfo;
            var csxFile   = debugInfo.bstrExe;

            debugInfo.bstrExe     = scriptcs;
            debugInfo.bstrArg     = $"\"{csxFile}\" -debug";
            debugInfo.clsidCustom = ManagedOnlyGuid;
            debugInfo.grfLaunch  |= (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
            return(debugInfo);
        }
Exemple #11
0
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = debugLaunchContext.LaunchConfiguration.GetValue(NodeExeKey, defaultValue: Nodejs.GetPathToNodeExecutableFromEnvironment());

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
            {
                SetupDebugTargetInfoForWebkitV2Protocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            string target = vsDebugTargetInfo.bstrExe;

            vsDebugTargetInfo.bstrExe = debugLaunchContext.LaunchConfiguration.GetValue <string>(NodeExeKey, Nodejs.GetPathToNodeExecutableFromEnvironment());
            string nodeJsArgs = vsDebugTargetInfo.bstrArg;

            vsDebugTargetInfo.bstrArg = "\"" + target + "\"";
            if (!string.IsNullOrEmpty(nodeJsArgs))
            {
                vsDebugTargetInfo.bstrArg += " ";
                vsDebugTargetInfo.bstrArg += nodeJsArgs;
            }

            vsDebugTargetInfo.clsidCustom = DebugEngine.AD7Engine.DebugEngineGuid;
            vsDebugTargetInfo.bstrOptions = "WAIT_ON_ABNORMAL_EXIT=true";
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Exemple #13
0
        public void SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = debugLaunchContext.LaunchConfiguration.GetValue(NodeExeKey, defaultValue: Nodejs.GetPathToNodeExecutableFromEnvironment());

            if (string.IsNullOrEmpty(nodeExe))
            {
                var workspace = this.WorkspaceService.CurrentWorkspace;
                workspace.JTF.Run(async() =>
                {
                    await workspace.JTF.SwitchToMainThreadAsync();

                    VsShellUtilities.ShowMessageBox(this.ServiceProvider,
                                                    string.Format(Resources.NodejsNotInstalledAnyCode, LaunchConfigurationConstants.LaunchJsonFileName),
                                                    Resources.NodejsNotInstalledShort,
                                                    OLEMSGICON.OLEMSGICON_CRITICAL,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                });

                // This isn't pretty but the only way to not get an additional
                // dialog box, after the one we show.
                throw new TaskCanceledException();
            }

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0) || NodejsProjectLauncher.CheckDebugProtocolOption())
            {
                SetupDebugTargetInfoForWebkitV2Protocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }
Exemple #14
0
        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);
        }
Exemple #15
0
 void IVsDebugLaunchTargetProvider2.UpdateContext(DebugLaunchActionContext debugLaunchContext)
 {
     // not needed
 }
        private void SetupDebugTargetInfoForInspectProtocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = vsDebugTargetInfo.bstrCurDir;

            var jsonContent = GetJsonConfigurationForInspectProtocol(target, cwd, nodeExe, debugLaunchContext);

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
        void IVsDebugLaunchTargetProvider.SetupDebugTargetInfo(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext)
        {
            var nodeExe = CheckNodeInstalledAndWarn(debugLaunchContext);

            var nodeVersion = Nodejs.GetNodeVersion(nodeExe);

            if (nodeVersion >= new Version(8, 0))
            {
                this.SetupDebugTargetInfoForInspectProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("ChromeV2", nodeVersion.ToString(), isProject: false);
            }
            else
            {
                this.SetupDebugTargetInfoForNodeProtocol(ref vsDebugTargetInfo, debugLaunchContext, nodeExe);
                TelemetryHelper.LogDebuggingStarted("Node6", nodeVersion.ToString(), isProject: false);
            }
        }
 /// <inheritdoc />
 public bool IsDebugLaunchActionSupported(DebugLaunchActionContext debugLaunchActionContext) {
     throw new NotImplementedException();
 }
 public void CustomizeLaunchConfiguration(DebugLaunchActionContext debugLaunchActionContext, IPropertySettings launchSettings) {
 }
        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);
        }
Exemple #21
0
        protected static string GetJsonConfigurationForInspectProtocol(string target, string workingDir, string nodeExe, DebugLaunchActionContext debugLaunchContext)
        {
            var debuggerPort     = debugLaunchContext.LaunchConfiguration.GetValue(DebuggerPortKey, defaultValue: NodejsConstants.DefaultDebuggerPort);
            var runtimeArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(NodeArgsKey, defaultValue: null));

            // If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
            runtimeArguments = runtimeArguments.Append($"--inspect-brk={debuggerPort}");
            var scriptArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(ScriptArgsKey, defaultValue: null));

            var launchConfig = new NodePinezorroDebugLaunchConfig(target,
                                                                  scriptArguments,
                                                                  nodeExe,
                                                                  runtimeArguments,
                                                                  debuggerPort.ToString(),
                                                                  workingDir,
                                                                  NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption(),
                                                                  null);


            return(JObject.FromObject(launchConfig).ToString());
        }
        private void SetupDebugTargetInfoForInspectProtocol(ref VsDebugTargetInfo4 vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = vsDebugTargetInfo.bstrCurDir;

            var jsonContent = GetJsonConfigurationForInspectProtocol(target, cwd, nodeExe, debugLaunchContext);

            vsDebugTargetInfo.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.guidLaunchDebugEngine = NodejsProjectLauncher.GetDebuggerGuid();
            vsDebugTargetInfo.bstrOptions           = jsonContent;
            vsDebugTargetInfo.LaunchFlags           = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Exemple #23
0
 public bool IsDebugLaunchActionSupported(DebugLaunchActionContext debugLaunchActionContext)
 {
     return(true);
 }
        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 bool IsDebugLaunchActionSupported(DebugLaunchActionContext debugLaunchActionContext) {
     return true;
 }
        private void SetupDebugTargetInfoForNodeProtocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = $"\"{vsDebugTargetInfo.bstrExe}\"";

            if (debugLaunchContext.LaunchConfiguration.TryGetValue <string>(ScriptArgsKey, out var scriptArgs) && !string.IsNullOrWhiteSpace(scriptArgs))
            {
                target += " " + scriptArgs;
            }
            vsDebugTargetInfo.bstrArg = target;

            vsDebugTargetInfo.bstrExe = nodeExe;
            if (debugLaunchContext.LaunchConfiguration.TryGetValue <string>(NodeArgsKey, out var nodeArgs) && !string.IsNullOrWhiteSpace(nodeArgs))
            {
                AppendOption(ref vsDebugTargetInfo, AD7Engine.InterpreterOptions, nodeArgs);
            }

            if (debugLaunchContext.LaunchConfiguration.TryGetValue <string>(DebuggerPortKey, out var debuggerPort) && !string.IsNullOrWhiteSpace(debuggerPort))
            {
                AppendOption(ref vsDebugTargetInfo, AD7Engine.DebuggerPort, debuggerPort);
            }
            AppendOption(ref vsDebugTargetInfo, AD7Engine.WaitOnNormalExitSetting, "true"); // todo: make this an option

            vsDebugTargetInfo.clsidCustom = AD7Engine.DebugEngineGuid;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;

            void AppendOption(ref VsDebugTargetInfo dbgInfo, string option, string value)
            {
                if (!string.IsNullOrWhiteSpace(dbgInfo.bstrOptions))
                {
                    dbgInfo.bstrOptions += ";";
                }

                dbgInfo.bstrOptions += option + "=" + HttpUtility.UrlEncode(value);
            }
        }
Exemple #27
0
        private void SetupDebugTargetInfoForNodeProtocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            var target = vsDebugTargetInfo.bstrExe;

            vsDebugTargetInfo.bstrExe = nodeExe;
            var nodeJsArgs = vsDebugTargetInfo.bstrArg;

            vsDebugTargetInfo.bstrArg = "\"" + target + "\"";
            if (!string.IsNullOrEmpty(nodeJsArgs))
            {
                vsDebugTargetInfo.bstrArg += " ";
                vsDebugTargetInfo.bstrArg += nodeJsArgs;
            }

            vsDebugTargetInfo.clsidCustom = DebugEngine.AD7Engine.DebugEngineGuid;
            vsDebugTargetInfo.bstrOptions = "WAIT_ON_ABNORMAL_EXIT=true";
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
 void ILaunchDebugTargetProvider.LaunchDebugTarget(IWorkspace workspaceContext, IServiceProvider serviceProvider, DebugLaunchActionContext debugLaunchActionContext)
 {
     // nope
 }
Exemple #29
0
        private void SetupDebugTargetInfoForWebkitV2Protocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            // todo: refactor the debugging and process starting so we can re-use

            var setupConfiguration = new SetupConfiguration();
            var setupInstance      = setupConfiguration.GetInstanceForCurrentProcess();
            var visualStudioInstallationInstanceID = setupInstance.GetInstanceId();

            // The Node2Adapter depends on features only in Node v6+, so the old v5.4 version of node will not suffice for this scenario
            // This node.exe will be the one used by the node2 debug adapter, not the one used to host the user code.
            var pathToNodeExe = Path.Combine(setupInstance.GetInstallationPath(), "JavaScript\\Node.JS\\v6.4.0_x86\\Node.exe");

            // We check the registry to see if any parameters for the node.exe invocation have been specified (like "--inspect"), and append them if we find them.
            var nodeParams = NodejsProjectLauncher.CheckForRegistrySpecifiedNodeParams();

            if (!string.IsNullOrEmpty(nodeParams))
            {
                pathToNodeExe = pathToNodeExe + " " + nodeParams;
            }

            var pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\extension\out\src\nodeDebug.js""");

            string trimmedPathToNode2DebugAdapter = pathToNode2DebugAdapterRuntime.Replace("\"", "");

            if (!File.Exists(trimmedPathToNode2DebugAdapter))
            {
                pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\out\src\nodeDebug.js""");
            }

            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = Path.GetDirectoryName(target); // Current working directory

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true),
                new JProperty("$adapter", pathToNodeExe),
                new JProperty("$adapterArgs", pathToNode2DebugAdapterRuntime));

            var jsonContent = configuration.ToString();

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrExe     = target;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Exemple #30
0
        protected static string GetJsonConfigurationForInspectProtocol(string target, string workingDir, string nodeExe, DebugLaunchActionContext debugLaunchContext)
        {
            var debuggerPort     = debugLaunchContext.LaunchConfiguration.GetValue(DebuggerPortKey, defaultValue: NodejsConstants.DefaultDebuggerPort);
            var runtimeArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(NodeArgsKey, defaultValue: null));

            // If we supply the port argument we also need to manually add --inspect-brk=port to the runtime arguments
            runtimeArguments = runtimeArguments.Append($"--inspect-brk={debuggerPort}");
            var scriptArguments = ConvertArguments(debugLaunchContext.LaunchConfiguration.GetValue <string>(ScriptArgsKey, defaultValue: null));

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("args", scriptArguments),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("runtimeArgs", runtimeArguments),
                new JProperty("port", debuggerPort),
                new JProperty("cwd", workingDir),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true));

            return(configuration.ToString());
        }
Exemple #31
0
        private void SetupDebugTargetInfoForWebkitV2Protocol(ref VsDebugTargetInfo vsDebugTargetInfo, DebugLaunchActionContext debugLaunchContext, string nodeExe)
        {
            // todo: refactor the debugging and process starting so we can re-use

            var target = vsDebugTargetInfo.bstrExe;
            var cwd    = Path.GetDirectoryName(target); // Current working directory

            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", target),
                new JProperty("runtimeExecutable", nodeExe),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("trace", NodejsProjectLauncher.CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true));

            var jsonContent = configuration.ToString();

            vsDebugTargetInfo.dlo         = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
            vsDebugTargetInfo.clsidCustom = NodejsProjectLauncher.WebKitDebuggerV2Guid;
            vsDebugTargetInfo.bstrExe     = target;
            vsDebugTargetInfo.bstrOptions = jsonContent;
            vsDebugTargetInfo.grfLaunch   = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;
        }
Exemple #32
0
 public void CustomizeLaunchConfiguration(DebugLaunchActionContext debugLaunchActionContext, IPropertySettings launchSettings)
 {
 }
Exemple #33
0
 /// <inheritdoc />
 public bool IsDebugLaunchActionSupported(DebugLaunchActionContext debugLaunchActionContext)
 {
     throw new NotImplementedException();
 }